This message was discovered on microsoft.public.dotnet.framework.drawing.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Josef Wainz |
how can i improve the quality of a saved gif?
the code below opens 3 gif files and merges them into 1 by using a bitmap. when i convert the bitmap back to gif the image quality is less than the gif quality i started with. i save it 2 ways, but it doesn't seem to make a difference.
any suggestions.
//create images from files Image map = Image.FromFile("C:\\Projects\\MapGen\\bin\\Debug\\Images\\Terminal463DrivetimeZones.gif", true); Image logo = Image.FromFile("C:\\Projects\\MapGen\\ctilogo2.gif", true); Image legend = Image.FromFile("C:\\Projects\\MapGen\\Legend\\Legend.gif", true);
//create bitmap Bitmap bm = new Bitmap(755, 480, PixelFormat.Format64bppPArgb);
//draw images onto bitmap Graphics g = Graphics.FromImage(bm); g.DrawImage(map, 1, 1); g.DrawImage(legend, 10, 440, 300, 25); g.DrawImage(logo, 380, 430, 90, 35);
//save as gif with encoderparameter EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter( Encoder.Quality, 75); ImageCodecInfo ici = GetEncoderInfo("image/gif"); bm.Save("C:\\Projects\\MapGen\\Brand\\BrandNew.gif", ici, eps);
//save as gif bm.Save("C:\\Projects\\MapGen\\Brand\\Brand.gif", ImageFormat.Gif);
|
|
|
| |
|
| |
| |
| John Hornick [MS] (VIP) |
Hi,
[Original message clipped]
meZones.gif", [Original message clipped]
GIF is not a lossy compression. It isn't the quality that's bad, it's the color table. GDI+ will always convert your image to 8bpp from 32bpp using a default "rainbow" palette. (btw, there's no need to try to use 64bpp. you might as well stick with 32bpp unless you have some reason to use 64.) Your image looks bad because it's being dithered into a stock selection of colors, rather than an optimal collection of colors.
To get a better looking image, you'll need to compose an optimal palette with which to save the image. See the following for more information: Q318343 INFO: GDI+ GIF Files Are Saved Using the 8-Bpp Format Q315780 HOWTO: Save a .gif File with a New Color Table By Using GDI+ Q319061 HOW TO: Save a .gif File with a New Color Table By Using Visual C# Q319591 HOW TO: Save a GIF with a New Color Table By Using Visual Basic.NET
Those articles tell you how to save a GIF with a color table of your choice. All that's left is to choose a color table. Look for median cut palette or octree palette or popularity palette on the web or in your favorite computer graphics books.
Thanks, - John Microsoft Developer Support This posting is provided "AS IS" with no warranties, and confers no rights. Visit http://www.microsoft.com/security for current information on security.
|
|
|
| |
|
|
| |
|
|
|
|
|