By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,221 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,221 IT Pros & Developers. It's quick & easy.

Resizing gif down. Quality suffers.

P: n/a
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.

Dec 28 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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!
***************************
"engwar" wrote:
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.

Dec 28 '05 #2

P: n/a
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.

Dec 28 '05 #3

P: n/a
engwar wrote:
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
Dec 29 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.