473,471 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Resizing gif down. Quality suffers.

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
3 1790
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ruby Tuesday | last post by:
I have a section(185pixelsx 185pixels) in my web page to display an image that is stored in a directory. Using php, how do you resize so if: the image dimension is smaller(width and height is...
0
by: Michael Rostkowski | last post by:
I posted this in alt.php, but as a reply, so now I'm posting it here for people who might have missed it but still could find it useful. Thanks to Andy Hassall for giving me good information. ...
6
by: Robert J. O'Hara | last post by:
I'm one of those people who practices what some consider "dull" and others consider "elegantly conservative" page design. I appreciate good traditional typography and standards-compliant liquid...
0
by: E | last post by:
I wrote code which Resizes images and then saves them below is the 2 methods. The problem is that half of the resized image turns out gray, as if it wasn't completed. Could someone please tell me...
0
by: E | last post by:
I wrote code which Resizes images and then saves them below is the 2 methods. The problem is that half of the resized image turns out gray, as if it wasn't completed. Could someone please tell me...
2
by: Thomas | last post by:
Hi all, I've written an image resizing class so that I can generate thumbnails and various image sizes on the fly. The problem I'm having is that on about 70% of the thumbnails I generate, I...
6
by: neverstill | last post by:
hi- So I wrote this nice little page that will allow the managers to add images to the products table. Without too many details to confuse everything, basically what I'm doing is: getting an...
8
by: berkshire | last post by:
Hi, Anyone know of a script out there that can resize images and not sacrifice image quality? I've been using phpthumb (http://phpthumb.sourceforge.net/) but when compared to an image resized...
1
by: Sinan Alkan | last post by:
Hi All, I have a method to resize any image file to the specific dimensions and save this new image to a path. I found it on a web page(By Joel Neubeck) and i changed it for my project. The...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.