Resizing gif down. Quality suffers.

E

engwar

I'm writing some file upload code using C# for users on my website. If
the image is too large I want to resize it smaller to a thumbnail size.
It's working fine for jpegs but the thumbnails of the gifs look pretty
bad.

I assume it's something to do with the color palette. I don't know a
whole lot about graphics programming. Can anyone assist?

Here's the code I'm currently using.

System.Drawing.Image img2 = new Bitmap(iImgWidthNew, iImgHeightNew,
PixelFormat.Format24bppRgb);
Graphics oGraphic = Graphics.FromImage(img2);
oGraphic.CompositingQuality = CompositingQuality.HighQuality ;
oGraphic.SmoothingMode = SmoothingMode.HighQuality ;
oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic ;
Rectangle oRectangle = new Rectangle(0, 0, iImgWidthNew,
iImgHeightNew);
oGraphic.DrawImage(objImage, oRectangle);

I get the same poor results if I don't pass a PixelFormat in the first
line.

I can see having quality suffer if I INCREASED the size of the image
but don't see why it suffers when I DECREASE it.

Would I have better results if I convert it to a .jpg and save it that
way? Most images uploaded will be photos but there might be some
illustrations uploaded as gifs.

Will I have a similar problem with png files?

Thanks for helping this newbie.
 
G

Guest

The GDI+ classes have a partial GIF implementation. Basically, you end up
with a 256 color bitmap no matter what and have little control over the end
product. I would suggest a third party image handling component.

Reason for GIF implementation: There are differing levels of licensing for
the patent and it gets expensive to have a full GIF engine.

If you cannot buy a library to handle this for you, and have to use GDI+,
you might want to look at these and see if they can help.

http://support.microsoft.com/kb/319061/en-us - C#
http://support.microsoft.com/kb/319591/en-us - VB.NET

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
E

engwar

Thanks for the information Gregory.

One question. In looking at the code provided at the Microsoft support
site it seems to go into detail about creating a new color table.

If I'm simply resizing an image would I need another color table? Seems
like the colors should be the same.

Perhaps I misunderstand as I've never created graphics using code and
this is all new.

Thanks again.
 
S

Stefan Simek

engwar said:
Thanks for the information Gregory.

One question. In looking at the code provided at the Microsoft support
site it seems to go into detail about creating a new color table.

If I'm simply resizing an image would I need another color table? Seems
like the colors should be the same.

Perhaps I misunderstand as I've never created graphics using code and
this is all new.

Thanks again.
The colors are not the same because you're using all the high-quality
settings. The colors from neighboring pixels are being interpolated,
etc., so you get many new colors in the new image. This can be a real
problem for GIF, I'd suggest using PNG for lossless compression instead.

HTH,
Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top