Geeks With Blogs

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

Lorin Thwaits A geek says what?

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.

Posted on Sunday, November 20, 2005 10:40 PM | Back to top


Comments on this post: GIF Transparency

# re: GIF Transparency
Requesting Gravatar...
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. :)
Left by Scott Cate - Knowledge Base Soft on Nov 21, 2005 2:47 PM

# re: GIF Transparency
Requesting Gravatar...
I use pixie to choose color but can not figure out how do you do it. Can you be more precise..
Left by Costa on May 05, 2009 1:05 AM

# re: GIF Transparency
Requesting Gravatar...
I've tried to run this in .NET 2, and got this error:


Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.
Left by Dan on Jul 20, 2009 7:21 AM

# re: GIF Transparency
Requesting Gravatar...
stop spamming boards ass hole
Left by you are a spammer on Mar 09, 2010 11:50 AM

# re: GIF Transparency
Requesting Gravatar...
Christian Louboutin Shoes Christian Louboutin Shoes
Christian Louboutin Boots Christian Louboutin Boots
Left by jcjc762 on Apr 01, 2010 2:45 AM

# re: GIF Transparency
Requesting Gravatar...
awesome!it's must a very useful software!thanks for your post!
Left by designerhandbags888 on Apr 10, 2010 2:25 AM

Your comment:
 (will show your gravatar)


Copyright © Lorin Thwaits | Powered by: GeeksWithBlogs.net