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/