[Translation] using GDI + in. Net to improve the picture quality of GIF images

Source: Internet
Author: User

// This article has www.blue1000.com translation, original address http://codebetter.com/blogs/brendan.tompkins/archive/2004/01/26/6103.aspx
// Respect the fruits of others' work. For details, please indicate the source.

GDI + is often used when writing a program. It can save a dark 32 BPP image as a GIF file, and the process is relatively simple. You can adjust the size of the GIF image before using the createthumnailimage method to save it.
Common Code:

System. Drawing. Bitmap B = new system. Drawing. Bitmap ("C: \ original_image.gif");
System. Drawing. Image thmbnail = B. getthumbnailimage (100,75, null, new intptr ());
Thmbnail. Save ("C: \ thumnail.gif", system. Drawing. imaging. imageformat. GIF );

The above code can plot and save GIF files, but soon you will find the problem: the quality of the generated thumnail.gif file is much lower than our expectation.
Slice:

As shown in, low-quality granular images also require "Color quantization" (palettization ). This problem occurs because the default 256 color is used by GDI +, and the actual color of the image is not taken into account.

Then, we tried to create our own "Palette", but the result was worse :). A good "Color quantization" algorithm should consider filling two pixel particles with a transitional color similar to the two pixels to provide more visible color space.
This is the "REE" algorithm. The "REE" algorithm allows us to insert our own algorithms to quantize our images.

Here are two Microsoft articles that may help us: KB 319061 and optimizing Color quantization for ASP. NET images (by Microsoft Morgan Skinner ). Morgan Skinner provides good "REE" algorithm code. You can download it for reference.

It is convenient to use octreequantizer:

System. Drawing. Bitmap B = new system. Drawing. Bitmap ("C: \ original_image.gif");
System. Drawing. Image thmbnail = B. getthumbnailimage (100,75, null, new intptr ());
Octreequantizer quantizer = new octreequantizer (255, 8 );
Using (Bitmap quantized = quantizer. quantize (thmbnail ))
{
Quantized. Save ("C: \ thumnail.gif", system. Drawing. imaging. imageformat. GIF );
}

Octreequantizer grayquantizer = new grayscalequantizer ();
Using (Bitmap quantized = grayquantizer. quantize (thmbnail ))
{
Quantized. Save ("C: \ thumnail.gif", system. Drawing. imaging. imageformat. GIF );
}

The film is as follows (is it more beautiful ?) :

Click here to download the project code and modify namespace to use it in your own project.

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.