473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ 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(iImgWidt hNew, iImgHeightNew,
PixelFormat.For mat24bppRgb);
Graphics oGraphic = Graphics.FromIm age(img2);
oGraphic.Compos itingQuality = CompositingQual ity.HighQuality ;
oGraphic.Smooth ingMode = SmoothingMode.H ighQuality ;
oGraphic.Interp olationMode = InterpolationMo de.HighQualityB icubic ;
Rectangle oRectangle = new Rectangle(0, 0, iImgWidthNew,
iImgHeightNew);
oGraphic.DrawIm age(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 1803
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(iImgWidt hNew, iImgHeightNew,
PixelFormat.For mat24bppRgb);
Graphics oGraphic = Graphics.FromIm age(img2);
oGraphic.Compos itingQuality = CompositingQual ity.HighQuality ;
oGraphic.Smooth ingMode = SmoothingMode.H ighQuality ;
oGraphic.Interp olationMode = InterpolationMo de.HighQualityB icubic ;
Rectangle oRectangle = new Rectangle(0, 0, iImgWidthNew,
iImgHeightNew);
oGraphic.DrawIm age(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
2863
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 less than 185pixels), display it in the center of the section if the width OR height is larger than 185pixel, resize them with aspect ratio maintained so both width and height is <= 185pixels. Then display it in the center of the section.
0
1880
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. I compared the smooth image resampling used in PHP to create good quality thumbnails of large images, used commonly in image galleries. i compared ImageMagick and PHP (with GD2) and compiled some statistics below. I ran two test. Both used a...
6
6199
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 displays, and I only reluctantly experiment with two-column layouts from time to time. One component of traditional book typography has always been the figure/caption combination. I haven't been following discussion on this topic for a year or...
0
1160
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 what could be the problem? I have pasted code below. Also this is a link to sample image that has the problem http://productionserver.no-ip.com/images/products/large/g2SPA0701.jpg private static Image imageResize(Image img, int newWidth, int...
0
1065
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 what could be the problem? I have pasted code below. Also this is a link to sample image that has the problem http://productionserver.no-ip.com/images/products/large/g2SPA0701.jpg private static Image imageResize(Image img, int newWidth, int...
2
2949
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 can see a 1 pixel border around the left and top edge. Not a huge deal but it's aggravating. Not sure what was causing it, I searched the net for code samples. Using code very similar to: http://www.codeproject.com/csharp/imageresize.asp
6
1926
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 Image from there I'm creating a new Bitmap(Image, int w, int h); then I'm saving that bitmap various encoder quality values.
8
3683
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 in photoshop it's products are not as good (yeah I upped the image quality and tried out some filters - no luck). Tutorials or scripts online preferred are preferred, but if you know of a way to change the settings on phpthumb to maintain the...
1
2145
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 code is as follows; --------------------------------- // usings part using System.Drawing; using System.Drawing.Imaging;
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7739
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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 we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.