Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Changing image dimensions and saving as a gif - comments much     appreciated

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
almurph@altavista.com - 19 Feb 2008 19:22 GMT
Hi,

   Hope you can help me wit this one. I have to open either a ".jpg",
".bmp" or a "gif" and alter its dimensions and save the output as
a .gif.

   Here is my attempt - I would greatly appreciate any comments/
suggestions/hints/things-to-be-award-of that you may like to offer
me:-

***** BEGIN CODE *****
//Firstly open the file into an image object
System.Drawing.Image img = Image.FromFile(fileName);

//Convert to bitmap with correct dimensions:
System.Drawing.Image newSizeImage = new Bitmap(img, 440, 60);

//Now convert the bitmap to a.gif
reSizeImage.Save("a.gif", System.Drawing.Imaging.ImageFormat.Gif);

****** END CODE ******

The only thing I notice is that the gif result looks a bit light. That
why I want some review of this approach. Perhaps I'm missing/
overlooking something - so any comments/suggestions that you may like
to offer me would be most appreciated.

Thanks in advance,
Al.
Peter Duniho - 19 Feb 2008 19:42 GMT
> [...]
> The only thing I notice is that the gif result looks a bit light. That
> why I want some review of this approach. Perhaps I'm missing/
> overlooking something - so any comments/suggestions that you may like
> to offer me would be most appreciated.

Unless you want to do a lot of extra work, I think the method you're using  
is about as good as you're going to get, at least with respect to the  
color (there are higher-quality ways to resample the resolution of the  
image, but you don't appear concerned about that).

GIF supports palettized images.  If you start with a non-palettized image,  
then .NET has to convert.  This will necessarily reduce the color space  
available and cause some discoloration of the image.  It won't always be  
"lighter", but it will always be different.

If you can preprocess the image so that it's only 8-bit palettized before  
converting to a GIF, then you should get better results, at least with  
respect to the saved GIF matching the bitmap just before saving.  But  
solving this in a general way is non-trivial, and for optimal results  
requires some interaction with the user, who is the only person who can  
tell your code whether the reduced-color image "looks right".

You might want to play with a full-blown image editing application (e.g.  
Photoshop, GIMP, etc.) that can do image format conversions to see what  
happens when you palettize non-palettized images.  Even in Photoshop (or  
Photoshop Elements), the most popular, widely used program, a GIF never  
looks quite as nice as an original 24-bit image.

You don't say what you're using the GIF output for, but for what it's  
worth, the PNG format offers in some respects the best of both worlds: the  
non-lossy compression and support of transparency of GIF with the  
full-color support of JPEG.  Your file size will be larger than for GIF,  
but it doesn't look like you're dealing with very large files to start  
with, and the quality will be much better.

Pete
almurph@altavista.com - 20 Feb 2008 10:38 GMT
On Feb 19, 7:42 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> On Tue, 19 Feb 2008 11:22:55 -0800, almu...@altavista.com  
>
[quoted text clipped - 36 lines]
>
> Pete

Pete - thanks a million for that response, esp the PNG stuff.

Cheers,
Al.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.