473,796 Members | 2,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sav e("a.gif", System.Drawing. Imaging.ImageFo rmat.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 1614
On Tue, 19 Feb 2008 11:22:55 -0800, al*****@altavis ta.com
<al*****@altavi sta.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...@nn owslpianmk.com>
wrote:
On Tue, 19 Feb 2008 11:22:55 -0800, almu...@altavis ta.com *

<almu...@altavi sta.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
4576
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
11099
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 window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin = window.open('images/KJV-THANKS.gif', 'Thanks', 'width=243,height=420,'); cwin.focus();
1
1439
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 correct EncType (multipart/form-data), so I would want it to set the EncType of the form. Can a control be done that extends on an already existing control - the one I have in mind is MetaBuilder FileUpload control...
15
5367
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 path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
3
1505
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 it's doing. Can anyone clarify this for me? ' I think this takes my current image (g) and then resizes it to what I want bmpImage = New Bitmap(g, newWidth, newHeight) ' now I set up a rectangle to the dimensions of the cropped version...
4
2757
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. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
1
2304
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 GUI. I have added the ability for the user to change the linear dimensions of the image (in pixels) and the quality of the image in order for the image to be saved in another file. I was wondering if is there a way to know in advance, based on...
9
9651
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 disk, I need to reference the disk file in our HR app. As part of the process, I'm resizing the image and changing its resolution from 96 to 72 dpi. If they are not at a 72 dpi resolution, the HR app freezes. The resizing works without a hitch, but...
8
2386
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 anyone spot why this may be happening? Should it only deteriate once upon intitially going through this procedure? The deterioration is subtle, but after a few iterations is quite noticeable..: private static System.Drawing.Image...
0
9685
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
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10465
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
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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
7558
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
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
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
2931
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.