469,631 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Compressing image colors:

I have a aspx page that outputs an image to the response.outputstream. 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(response.outputstream,ImageFormat.Gi f)
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, programmatically, that might work too.

Thanks for any help!!!
Nov 15 '05 #1
4 3404
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.com.

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!

http://www.dotnetforums.net/t74693.html
Regards,
Fergus
Nov 15 '05 #2
Thanks! I'll give it a look!

-D

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:O3**************@tk2msftngp13.phx.gbl...
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.com.

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!

http://www.dotnetforums.net/t74693.html
Regards,
Fergus

Nov 15 '05 #3
"MC D" <as***@earthtalk.com> wrote in message news:<uX**************@TK2MSFTNGP11.phx.gbl>...
I have a aspx page that outputs an image to the response.outputstream. 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(response.outputstream,ImageFormat.Gi f)
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, programmatically, that might work too.

Thanks for any help!!!


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
Nov 15 '05 #4
"MC D" <as***@earthtalk.com> wrote in message news:<uX**************@TK2MSFTNGP11.phx.gbl>...
I have a aspx page that outputs an image to the response.outputstream. 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(response.outputstream,ImageFormat.Gi f)
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, programmatically, that might work too.

Thanks for any help!!!


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
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Laszlo Zsolt Nagy | last post: by
3 posts views Thread by Mr. x | last post: by
3 posts views Thread by MC D | last post: by
reply views Thread by bearophileHUGS | last post: by
1 post views Thread by jitu78 | last post: by
1 post views Thread by oruccim | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.