Comparison | Compression just helps a friend to do a picture management tool, originally his program is using ASP, but the ASP in some server aspect function really lacks, therefore I use. NET gave him a small picture upload tool pictures in the upload should be based on the size of the picture to generate the corresponding size of the small map, such as 760PX of pictures, then to generate more than 300,100 width of the picture. So look at the function of GDI, ~ ~ usually not used much, unfamiliar ah.
There are 2 ways to implement this method:
1. Use the Getthumbnailimage method of image to generate a compressed picture directly, probably so:
file://set the EncoderParameters object of the original picture object, set the sharpness
ImageCodecInfo ici = Getcodecinfo ((string) htmimes[mfileextname]);
EncoderParameters parameters = new EncoderParameters (1);
Parameters. Param[0] = new Encoderparameter (encoder.quality,lngdefinition);
System.Drawing.Image.GetThumbnailImageAbort Mycallback =new
System.Drawing.Image.GetThumbnailImageAbort (Thumbnailcallback);
System.Drawing.Image Mythumbnail = Image. Getthumbnailimage (Intnewwidth, Intnewheight,
Mycallback, IntPtr.Zero);
Mythumbnail.save (Txtnewpath, ICI, parameters);
2. Redraw an image using graphics
ImageCodecInfo ici = Getcodecinfo ((string) htmimes[mfileextname]);
EncoderParameters parameters = new EncoderParameters (1);
Parameters. Param[0] = new Encoderparameter (encoder.quality,lngdefinition);
Bitmap Objnewbitmap = new Bitmap (Intnewwidth, Intnewheight, Pixelformat.format32bppargb);
Creates a new Graphics object from the specified Image object
Graphics objgraphics = Graphics.fromimage (Objnewbitmap);
Clear the entire drawing surface and fill with a transparent background color
Objgraphics.clear (color.transparent);
Draws the original picture object at the specified location and at the specified size
Objgraphics.drawimage (Image, new Rectangle (0, 0, intnewwidth, intnewheight));
Objnewbitmap.save (Txtnewpath + txtnewfilename+ ".") +mfileextname, ICI, parameters);
Note that lngdefinition is a long parameter that adjusts the sharpness, and generally 50-90 is clear.
Because in the use of the first method, the results found that the sharpness of the high is very vague, and then use the 2nd method, found that the definition of 40 is also very clear.
A summary of the following bar:
1. 2 effects, graphics wins in sharpness
2. In generating the same width, the same definition of the premise, the picture graphics drawing is also relatively small, small 1/3 or so.
So it seems that Ms image compression Getthumbnailimage method should not fit in the compression picture, that is suitable for where to use it, I hope the familiar people tell the next OH