C # generates HD thumbnail code, a C # function module, contains annotations, followed by function parameters, see this C # generated thumbnail code:
01public static void Setgoodimage (String fileName, string newFile, int maxheight, int maxwidth,long qualitys)
229
if (qualitys = 0)
04 {
Qualitys = 80;
06}
Modified using (System.Drawing.Image img = System.Drawing.Image.FromFile (fileName))
08 {
System.Drawing.Imaging.ImageFormat
Ten Thisformat = img. Rawformat;
One Size newsize = newsize (maxwidth, MaxHeight, IMG. Width, IMG. Height);
Bitmap outbmp = new Bitmap (newsize.width, newsize.height);
Graphics g = graphics.fromimage (outbmp);
14//Set the painting quality of the canvas
g.compositingquality = compositingquality.highquality;
G.smoothingmode = smoothingmode.highquality;
G.interpolationmode = Interpolationmode.highqualitybicubic;
G.drawimage (IMG, new Rectangle (0, 0, Newsize.width, newsize.height),
0, 0, IMG. Width, IMG. Height, GraphicsUnit.Pixel);
G.dispose ();
21//The following code to save the picture, set the compression quality
EncoderParameters encoderparams = new EncoderParameters ();
long[] quality = new LONG[1];
Quality[0] = Qualitys;
Encoderparameter Encoderparam = new Encoderparameter (System.Drawing.Imaging.Encoder.Quality, Quality);
Encoderparams.param[0] = Encoderparam;
27//Get the ImageCodecInfo object containing information about the built-in image codec.
imagecodecinfo[] Arrayici = Imagecodecinfo.getimageencoders ();
ImageCodecInfo jpegici = null;
for (int x = 0;
x < arrayici.length;
X + +)
33 {
if (Arrayici[x]. Formatdescription.equals ("JPEG"))
35 {
Jpegici = Arrayici[x];
37//Set JPEG encoding
break;
39}
40}
if (Jpegici!= null)
42 {
Outbmp.save (NewFile, Jpegici, encoderparams);
44}
Or else
46 {
Outbmp.save (NewFile, Thisformat);
48}
The IMG. Dispose ();
Outbmp.dispose ();
51}
52}
Function parameter Description:
View sourceprint?1///Original file
2///New File
3///Max Height
4///Max width
5///quality, if 0, then set to 80
Note : Please pay attention to the triple programming Tutorials section for more wonderful articles .