// reference the namespace
using system. Drawing. imaging;
using system. Drawing;
using system. Drawing. drawing2d;
# Region getpicthumbnail // <summary> // lossless compression image /// </Summary> /// <Param name = "sfile"> original image </param>/ // <Param name = "dfile"> storage location after compression </param> /// <Param name = "dheight"> height </param> /// <Param name = "dwidth"> </param> // <Param name = "flag"> Compression Quality: 1-100 </param> // <returns> </returns> Public bool getpicthumbnail (string sfile, string dfile, int dheight, int dwidth, int flag) {system. drawing. image isource = system. drawing. image. fromfile (sfile); imageformat tformat = isource. rawformat; int Sw = 0, SH = 0; // proportional scaling size tem_size = new size (isource. width, isource. height); If (tem_size.width> dheight | tem_size.width> dwidth) // change ** to the OR operator symbol in C # {If (tem_size.width * dheight)> (tem_size.height * dwidth) {Sw = dwidth; SH = (dwidth * tem_size.height)/rotate;} else {SH = dheight; Sw = (tem_size.width * dheight)/tem_size.height ;}} else {Sw = tem_size.width; SH = tem_size.height;} bitmap Ob = new Bitmap (dwidth, dheight); graphics G = graphics. fromimage (OB); G. clear (color. whitesmoke); G. compositingquality = compositingquality. highquality; G. smoothingmode = smoothingmode. highquality; G. interpolationmode = interpolationmode. highqualitybicubic; G. drawimage (isource, new rectangle (dwidth-SW)/2, (dheight-SH)/2, SW, SH), 0, 0, isource. width, isource. height, graphicsunit. pixel); G. dispose (); // The following Code To save the image, set the compression quality encoderparameters Ep = new encoderparameters (); long [] Qy = new long [1]; QY [0] = flag; // set the compression ratio to 1-100 encoderparameter eparam = new encoderparameter (system. drawing. imaging. encoder. quality, QY); EP. param [0] = eparam; try {imagecodecinfo [] arrayici = imagecodecinfo. getimageencoders (); imagecodecinfo effeciciinfo = NULL; For (INT x = 0; x <arrayici. length; X ++) {If (arrayici [X]. formatde Response. Equals ("Jpeg") {response iciinfo = arrayici [X]; break ;}} if (Response iciinfo! = NULL) {ob. save (dfile, effeciciinfo, EP); // dfile is the new path after compression} else {ob. save (dfile, tformat);} return true;} catch {return false;} finally {isource. dispose (); ob. dispose () ;}# endregion