GIF Transparency

Have you ever tried to create a transparent GIF with GDI+?  Seems like it should be easy since there's such a thing as Color.Transparent, but interestingly enough the GIF encoder that's included with the .NET framework doesn't correctly identify Color.Transparent!  But there is a way to get the job done by using unsafe code blocks to directly access the memory where the bitmap is held.  Here is a fun WinForms sample that allows you to read in any GIF file and set any color in the palette to be transparent:



It will load in any GIF image, and as you mouse over the image you can click on the color you want to be transparent.  You'll know what color you're selecting because the whole background of the form will turn that color.  Once you click, a Save Dialog box opens and your new GIF with transparency is saved.

You can download the source code to the solution here.  It was made in .NET 1.1, but will convert easily to 2.0.


Feedback

# re: GIF Transparency

Lorin, Over the weekend I thoguht of a quick little project you could do wtih GDI+. Just an idea, no rush on it.

Take a static picture, and make it much more enjoyable to look at. Add a little tilt, maybe 10 degrees, so it's leaning back, and then, add a reflection, like it's sitting on a table. Maybe 20% of the picture is reflected.

It would be a great little server control. Not putting you o the spot, but if you're looking for something to do. :) 11/21/2005 2:47 PM | Scott Cate - Knowledge Base Soft

# re: GIF Transparency

nmbmb 2/4/2007 7:24 PM | nmn,

Post a comment





 

Please add 4 and 4 and type the answer here:

News


Welcome to my blog.
Here's what we've got on the menu today:

Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

Syndication: