473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Changing image dimensions and saving as a gif - comments muchappreciated

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

Similar topics

7
by: Yang Li Ke | last post by:
Hi guys! If someone post a link to an image like this: http://ia.imdb.com/media/imdb/01/I/57/18/16m.jpg Is there any ways to find the images width and height? Thank you! -- Yang
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
1
by: Sam Collett | last post by:
How would you go about create a web control that allows you to upload images and limit the dimensions (width/height) of the image? The control may be put on any page, which may not contain the...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
3
by: Darrel | last post by:
I've been trying to figure out how to crop an image. I found the sample code below, but I'm not exactly sure what it's doing. I've added my own comments as best I can trying to explain what I think...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
1
by: Andrea Gavana | last post by:
Hello NG, sorry if the message is not strictly Python-related, but it is fantastically impossible to send post to Image-SIG. I am using PIL to load and display some pictures (via wxPython) in a...
9
by: kombu67 | last post by:
I'm reading a series of images from a MS SQL table and saving them to directory. These are staff ID pictures from our security card app. Once I've extracted the ID photo from the security app to...
8
by: JJ | last post by:
Whilst I am resizing images I am losing quality. This is only happening in small amounts, but if you repeatedly put the same image through the following code, the image quality slowly degrades. Can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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
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...

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.