Changing image dimensions and saving as a gif - comments muchappreciated

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • almurph@altavista.com

    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.
  • Peter Duniho

    #2
    Re: Changing image dimensions and saving as a gif - comments much appreciated

    On Tue, 19 Feb 2008 11:22:55 -0800, almurph@altavis ta.com
    <almurph@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

    Comment

    • almurph@altavista.com

      #3
      Re: Changing image dimensions and saving as a gif - comments muchappreciated

      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.

      Comment

      Working...