Groups | Blog | Home
all groups > dotnet drawing api > january 2007 >

dotnet drawing api : Only Gifs have indexed pixel formats?



Jim Light
1/18/2007 10:47:29 PM
Hi,

I know that Gif images have an indexed pixel format, However it is
possible for Tiffs and jpegs to also have this format?

Thank you for your time.

Regards,

Jim.
Bob Powell [MVP]
1/19/2007 8:40:47 AM
Tiff can because tiff does everything, I don't think jpeg can.

Even though tiff can support the format the GDI+ codecs don't support
this version of tiff encoding.

The other types of indexed format supported by GDI+ is the fax format of
1 bit per pixel and the 4 bit per pixel 16 colour.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
Jim Light
1/19/2007 4:03:52 PM
Hi Bob,

Thank you for your informative answer! The reason I asked is as
follows:

II wrote a small C# routine that resizes images from a stream input.
During a test of the routine, I tried to upload a gif file and got the
following error:

"A Graphics object cannot be created from an image that has an indexed
pixel format."

then I changed the line "Bitmap bitmap = new Bitmap(width, heigth,
img.PixelFormat);"

to

"Bitmap bitmap = new Bitmap(width, heigth);"

Now I can create a Graphics object from a gif file. However, since this
problem occured, I can't be sure that all different types of gifs,
jpegs, and tiffs can be processed by this routine correctly. Is there a
way to be sure?

Thank you.

Regards,

Jim

[quoted text, click to view]
Michael Phillips, Jr.
1/19/2007 7:20:44 PM
It is not possible to create a Graphics object from an indexed pixel format.
It was a design decision, unfortunately.

However, you may load and save indexed pixel formatted images. You can test
the pixel format by examining the PixelFormat property after the image is
loaded.

You can still work with indexed pixel formatted images with a Graphics
object provided that you convert the image to 32bpp as you did by creating a
bitmap from your gif.

Otherwise, you may use LockBits and work with indexed pixel formatted images
with their raw scanlines.

When you save your bitmap as a gif, the encoder will reduce the color depth
to 8bpp but you may not be happy with the result of the color reduction. If
not, you will have to use color quantization to reduce a 32bpp image to an
indexed color image to get the best color matches.


[quoted text, click to view]

AddThis Social Bookmark Button