In C #, bitmap can be saved as GIF by default, but the GIF stored in this method will be seriously distorted.
Under normal circumstancesCode:
1 System. Drawing. Bitmap B = New System. Drawing. Bitmap ("C: \ original_image.gif");
2 System. Drawing. Image thmbnail = B. getthumbnailimage ( 100 , 75 , Null , New Intptr ());
3 Thmbnail. Save ("C: \ thumnail.gif", system. Drawing. imaging. imageformat. GIF );
Today, I am going to write a software program for batch processing images, including various processing methods and effects. However, when I saved the images as GIF, I encountered a problem and checked it online for a long time.
There is no way to improve the quality of GIF images. Many people are asking this question, but few people have answered the question correctly.
I finally found a solution to reduce the size of the saved GIF, but the effect basically conforms to the regular
The method in this example is "REE".Algorithm. The "REE" algorithm allows us to insert our own algorithms to quantize our images.
A good "Color quantization" Algorithm You should consider filling in a transitional color that is similar to the color of these two pixels between two pixel particles to provide more visible color space.
Morgan Skinner provides good "REE" algorithm code. You can download it for reference.
It is convenient to use octreequantizer:
1 System. Drawing. Bitmap B = New System. Drawing. Bitmap ("C: \ original_image.gif");
2 System. Drawing. Image thmbnail = B. getthumbnailimage ( 100 , 75 , Null , New Intptr ());
3 Octreequantizer Quantizer = New Octreequantizer ( 255 , 8 );
4 Using (Bitmap quantized = Quantizer. quantize (thmbnail ))
5 {
6 Quantized. Save ("C: \ thumnail.gif", system. Drawing. imaging. imageformat. GIF );
7 }
8 Octreequantizer grayquantizer = New Grayscalequantizer ();
9 Using (Bitmap quantized = Grayquantizer. quantize (thmbnail ))
10 {
11 Quantized. Save ("C: \ thumnail.gif", system. Drawing. imaging. imageformat. GIF );
12 }
You can click here to download the class file (project file). According to my trial, only two class files (octreequantizer. CS, quantizer. CS). Change the namespace of these two class files
The name of your project is enough. You also need to compile the project in unsafe compilation mode. Right-click the project name and select "allow Insecure code" in the Generation tab.