Click here to Skip to main content
12,999,010 members (46,089 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 8 Aug 2006

VB.Net GIF Transparency

, 8 Aug 2006
Rate this:
Please Sign up or sign in to vote.
A method of creating transparent GIF image from a source GIF image.
<!-- Article Starts - DO NOT ADD HTML/BODY START TAGS-->


I have searched the web (via Google) for examples on how to convert a GIF image into a transparent GIF image without much success. What I wanted was there, just not in the way I wanted it.

Some of the methods I've seen on the web that converts a non-transparent GIF to a transparent GIF used unsafe code to perform the conversions. With luck, I stumbled across a couple of examples that performed the conversion without unsafe code, and I ran into Bob Powell's transparency page and voila, found what I was looking for. Although what I was looking for was there, it was mixed in with the UI code and not put together in a way I could understand. So I took Bob's code, moved the code that did the conversion into it's own class, put some extra comments in there, re-formatted the code, and changed some variable names.

Using the code

The GifConverter class contains a single public shared method, GetTransparentGif. This class takes two arguments, Image (Bitmap) and TransparentColor (Color). The Image argument is the image to be converted. The original image is not touched, instead the image is "copied" to a new image that the method returns. The TransparentColor argument is the color within the palette that will be set as the color to make transparent. There are currently no checks within the method to verify the source image is a GIF image.

Points of Interest

Instead of using unsafe code to perform the copy, this library uses the System.Runtime.Marshal class to perform bit-by-bit reading/writing to effectively copy the source bitmap's data to the destination bitmap. I learned a lot rewriting the original by Bob Powell into a usable library.


v1.0 Initial Release <!------------------------------- That's it! --------------------------->


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
I have worked, on a daily basis, with C#, VB.Net, VB 6, Javascript, VBScript, legacy ASP using Javascript and VBScript, Perl, SQL, Small(C), DHTML, HTML, XML, C and some C++ in *nix environment. Currently, I'm learning COBOL on an IBM mainframe.

My favorite development projects include developing the Windows Form Controls and Web Controls in .Net. Primarily, the design-time classes (Designer and TypeConverters) for controls and classes, and GDI+.

You may also be interested in...

Comments and Discussions

GeneralTransparent Background depends on color quantize method Pin
Karl-Werner Rieger7-May-09 12:37
memberKarl-Werner Rieger7-May-09 12:37 
GeneralDo not work... Pin
abaco1235-Dec-06 3:18
memberabaco1235-Dec-06 3:18 
GeneralRe: Do not work... Pin
Mythran6-Dec-06 6:49
memberMythran6-Dec-06 6:49 
GeneralRe: Do not work... Pin
abaco1237-Dec-06 2:39
memberabaco1237-Dec-06 2:39 
QuestionTransparent color [modified] Pin
dshorter115-Aug-06 9:09
memberdshorter115-Aug-06 9:09 
AnswerRe: Transparent color Pin
davehale2318-Sep-07 5:34
memberdavehale2318-Sep-07 5:34 
GeneralWhy not ... Pin
dotnetvirgin8-Aug-06 19:02
memberdotnetvirgin8-Aug-06 19:02 
GeneralRe: Why not ... Pin
Mythran9-Aug-06 5:38
memberMythran9-Aug-06 5:38 
GeneralRe: Why not ... Pin
dotnetvirgin9-Aug-06 12:30
memberdotnetvirgin9-Aug-06 12:30 
GeneralRe: Why not ... Pin
Mythran14-Aug-06 9:20
memberMythran14-Aug-06 9:20 
GeneralRe: Why not ... Pin
dotnetvirgin15-Aug-06 13:23
memberdotnetvirgin15-Aug-06 13:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 8 Aug 2006
Article Copyright 2006 by Mythran
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid