Compressing image colors:

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MC D

    #1

    Compressing image colors:

    I have a aspx page that outputs an image to the response.output stream. This
    works great. However, I want to be able to make the image it outputs a .gif
    file. I can change the output type to "image/gif" and save the image by
    doing:

    myBitmap.Save(r esponse.outputs tream,ImageForm at.Gif)
    and this works, BUT it uses a horrible halftone palette to reduce the
    colors. I have been trying for a day and a half to figure out any way to
    reduce the colors into a .gif with no success. You can see the articles at:
    http://support.microsoft.com/default...;EN-US;Q319591 and
    http://support.microsoft.com/default...;EN-US;Q319061 which
    actually work, but only in grayscale. Does anyone have any ideas of a way to
    do this?

    OR

    I have also tried outputting the file as a PNG, which works, but because
    (for whatever reason), the png always comes out darker than the original,
    and I need the background color of my image to match the background color on
    the site. SOOOooo... If someone can tell me how to make a background color
    of a png transparent, programmaticall y, that might work too.

    Thanks for any help!!!


  • Fergus Cooney

    #2
    Re: Compressing image colors:

    Hi MC D,

    Strange things happen. Only today I was browsing on a totally different
    question and came across this

    Color Quantization and GDI+ GIF with much better quality
    This sample shows how to decrease colors in an image from 24bit to 8 bit. And
    various other numbers of colors as well, from 8 to 256. Quantization is done
    by using an octree. Many thanks to vbaccelerator.c om.

    GDI+ uses a halftone palette by default to save the image to file. This leads
    to terrible quality in many cases. This sample greatly improves the saved GIF
    image. Enjoy!




    Regards,
    Fergus


    Comment

    • MC D

      #3
      Re: Compressing image colors:

      Thanks! I'll give it a look!

      -D

      "Fergus Cooney" <filter-1@tesco.net> wrote in message
      news:O3gWkheiDH A.3328@tk2msftn gp13.phx.gbl...[color=blue]
      > Hi MC D,
      >
      > Strange things happen. Only today I was browsing on a totally[/color]
      different[color=blue]
      > question and came across this
      >
      > Color Quantization and GDI+ GIF with much better quality
      > This sample shows how to decrease colors in an image from 24bit to 8 bit.[/color]
      And[color=blue]
      > various other numbers of colors as well, from 8 to 256. Quantization is[/color]
      done[color=blue]
      > by using an octree. Many thanks to vbaccelerator.c om.
      >
      > GDI+ uses a halftone palette by default to save the image to file. This[/color]
      leads[color=blue]
      > to terrible quality in many cases. This sample greatly improves the saved[/color]
      GIF[color=blue]
      > image. Enjoy!
      >
      > http://www.dotnetforums.net/t74693.html
      >
      >
      > Regards,
      > Fergus
      >
      >[/color]


      Comment

      • Glenn Randers-Pehrson

        #4
        Re: Compressing image colors:

        "MC D" <aspam@earthtal k.com> wrote in message news:<uXvSiYeiD HA.3204@TK2MSFT NGP11.phx.gbl>. ..[color=blue]
        > I have a aspx page that outputs an image to the response.output stream. This
        > works great. However, I want to be able to make the image it outputs a .gif
        > file. I can change the output type to "image/gif" and save the image by
        > doing:
        >
        > myBitmap.Save(r esponse.outputs tream,ImageForm at.Gif)
        > and this works, BUT it uses a horrible halftone palette to reduce the
        > colors. I have been trying for a day and a half to figure out any way to
        > reduce the colors into a .gif with no success. You can see the articles at:
        > http://support.microsoft.com/default...;EN-US;Q319591 and
        > http://support.microsoft.com/default...;EN-US;Q319061 which
        > actually work, but only in grayscale. Does anyone have any ideas of a way to
        > do this?
        >
        > OR
        >
        > I have also tried outputting the file as a PNG, which works, but because
        > (for whatever reason), the png always comes out darker than the original,
        > and I need the background color of my image to match the background color on
        > the site. SOOOooo... If someone can tell me how to make a background color
        > of a png transparent, programmaticall y, that might work too.
        >
        > Thanks for any help!!![/color]

        If you are using MSIE to view the images, they appear darker because
        MSIE mishandles the gamma data. Try removing the gAMA chunk and
        using only the sRGB chunk, and see if the color level is better.
        You can use the pngcrush application from an MSDOS window to do this.

        pngcrush -rem gama -srgb 1 in.png temp.png

        Get pngcrush from the DOWNLOAD link at http://pmt.sf.net/pngcrush

        Glenn

        Comment

        • Glenn Randers-Pehrson

          #5
          Re: Compressing image colors:

          "MC D" <aspam@earthtal k.com> wrote in message news:<uXvSiYeiD HA.3204@TK2MSFT NGP11.phx.gbl>. ..[color=blue]
          > I have a aspx page that outputs an image to the response.output stream. This
          > works great. However, I want to be able to make the image it outputs a .gif
          > file. I can change the output type to "image/gif" and save the image by
          > doing:
          >
          > myBitmap.Save(r esponse.outputs tream,ImageForm at.Gif)
          > and this works, BUT it uses a horrible halftone palette to reduce the
          > colors. I have been trying for a day and a half to figure out any way to
          > reduce the colors into a .gif with no success. You can see the articles at:
          > http://support.microsoft.com/default...;EN-US;Q319591 and
          > http://support.microsoft.com/default...;EN-US;Q319061 which
          > actually work, but only in grayscale. Does anyone have any ideas of a way to
          > do this?
          >
          > OR
          >
          > I have also tried outputting the file as a PNG, which works, but because
          > (for whatever reason), the png always comes out darker than the original,
          > and I need the background color of my image to match the background color on
          > the site. SOOOooo... If someone can tell me how to make a background color
          > of a png transparent, programmaticall y, that might work too.
          >
          > Thanks for any help!!![/color]

          If you are using MSIE to view the images, they appear darker because
          MSIE mishandles the gamma data. Try removing the gAMA chunk and
          using only the sRGB chunk, and see if the color level is better.
          You can use the pngcrush application from an MSDOS window to do this.

          pngcrush -rem gama -srgb 1 in.png temp.png

          Get pngcrush from the DOWNLOAD link at http://pmt.sf.net/pngcrush

          Glenn

          Comment

          Working...