The problem is that GDI+ doesn't have very good support for indexed images, such as GIF. The main problems are that you can not use a Graphics object on a indexed image, and you have very limited control over the color palette. In you example above, GDI+
is converting the indexed GIF into a 32-bit RGB image. It is then performing the graphics manipulation and then converting the image back into an indexed GIF. However, the transparent color is not retained in the conversion. Because it is working with the
image as a 32-bit RGB image, it ignores your attempt to set the color palette.
Here are a couple of links that talk about the issue and give a work-around for it. I personally like the first link best because it does not use unsafe code blocks.
Participant
1993 Points
438 Posts
Re: Resizing GIFs and maintaining transparency
Dec 22, 2008 11:53 AM|Benners_J|LINK
The problem is that GDI+ doesn't have very good support for indexed images, such as GIF. The main problems are that you can not use a Graphics object on a indexed image, and you have very limited control over the color palette. In you example above, GDI+ is converting the indexed GIF into a 32-bit RGB image. It is then performing the graphics manipulation and then converting the image back into an indexed GIF. However, the transparent color is not retained in the conversion. Because it is working with the image as a 32-bit RGB image, it ignores your attempt to set the color palette.
Here are a couple of links that talk about the issue and give a work-around for it. I personally like the first link best because it does not use unsafe code blocks.
http://ewbi.blogs.com/develops/2005/08/sparklines_22.html
http://www.bobpowell.net/giftransparency.htm
http://support.microsoft.com/kb/319061
Good Luck!