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

Changing image dimensions and saving as a gif - comments muchappreciated

P: n/a
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.
Feb 19 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 19 Feb 2008 11:22:55 -0800, al*****@altavista.com
<al*****@altavista.comwrote:
[...]
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
Feb 19 '08 #2

P: n/a
On Feb 19, 7:42*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Tue, 19 Feb 2008 11:22:55 -0800, almu...@altavista.com *

<almu...@altavista.comwrote:
[...]
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
Pete - thanks a million for that response, esp the PNG stuff.

Cheers,
Al.
Feb 20 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.