How to crop part of gif image?
Question
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.
Solution
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow