A comparison of the 2 ways in which. NET produces compressed pictures

Source: Internet
Author: User
Tags comparison
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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.