Multimobile Development: Building Applications for any Smartphone
bmp to gif image quality
Messages   Related Types
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);
Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
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.

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Drawing.Bitmap
System.Drawing.Graphics
System.Drawing.Imaging.EncoderParameter
System.Drawing.Imaging.EncoderParameters
System.Drawing.Imaging.ImageCodecInfo
System.Drawing.Imaging.ImageFormat
System.Drawing.Imaging.PixelFormat
System.Text.Encoder
System.Web.UI.MobileControls.Image




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734