views:

1109

answers:

2

Hi every one,

i wrote some code to crop large image to small one.

Everything is OK but when i tried GIF images i get the following exception

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

I'm using Graphics class to do this

Graphics gfx = Graphics.FromImage(croppedBitmap)

thank you.

A: 

codeproject - Resizing a Photographic image with GDI+ for .NET

mangokun
I think the OP was after a way to correct the error rather than a different library?
Jon Cage
+2  A: 

The pixels of GIF images are not RGB values, they are indexes of a color table array stored in the header of the file. Graphic objects only support non-indexed pixel format. If you want to use the Graphic object, you must convert your image into a non-indexed pixel format.

This is exactly what this guy did: http://www.codeproject.com/KB/cs/WriteTextToGif.aspx?display=PrintAll

Exxos
Thank u;But i want to do this without changing the image type and resolution.!
Wahid Bitar
Then I would do the work with a Bitmap object:Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);Bitmap cropped = bitmap.Clone(rect, bitmap.PixelFormat);return cropped;
Exxos