Asp.net uses Color quantization to improve GIF image quality (scaling and watermarking)

Source: Internet
Author: User

In Asp.net, the GDI + has a strong image operation function and good effect. However, when you output GIF images, you will find that the image quality is poor, and the output JPG, comparing PNG and BMP formats, there is a big gap and the image effect is somewhat unacceptable.

Here is a method provided by Microsoft's msdn to improve the effect of the generated GIF image.

. Net high-quality thumbnails, transparent image watermarks, text watermarks Source Code released in the article, has provided the implementation method, this is not involved here.

Improve the effect of GIF Image Generation. Here we use Color quantization, that is, the color-colored palette of the duplicate plot.

Let's take a look at several comparison images:

Image generated by Asp.net by default

Color quantified Image

 

PassColor quantizationAs you can see, the effect is already quite good.

This Color quantization class library is also very simple:

Using (bitmap BMP = new Bitmap (...)) {octreequantizerquantizer = new octreequantizer (255, 8); // two parameters are the color value and the color depth using (Bitmap quantized = quantizer. quantize (image) {response. contenttype = "image/GIF"; quantized. save (response. outputstream, imageformat. GIF );}}

This library comes from msdn, the original address: http://msdn.microsoft.com/en-us/library/aa479306.aspx

The source code was upgraded from triangular cat to. NET 2.0, and some modifications and a little Chinese were made. The copyright belongs to the original author.

Download source code and example

Original article: http://www.zu14.cn/2008/12/25/aspnet_gif_quantize/

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.