Click here to Skip to main content
Click here to Skip to main content

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-->

Introduction

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.

History

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

License

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

Mythran
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+.

Comments and Discussions

 
GeneralTransparent Background depends on color quantize method PinmemberKarl-Werner Rieger7-May-09 12:37 
GeneralDo not work... Pinmemberabaco1235-Dec-06 3:18 
GeneralRe: Do not work... PinmemberMythran6-Dec-06 6:49 
GeneralRe: Do not work... Pinmemberabaco1237-Dec-06 2:39 
QuestionTransparent color [modified] Pinmemberdshorter115-Aug-06 9:09 
AnswerRe: Transparent color Pinmemberdavehale2318-Sep-07 5:34 
GeneralWhy not ... Pinmemberdotnetvirgin8-Aug-06 19:02 
GeneralRe: Why not ... PinmemberMythran9-Aug-06 5:38 
GeneralRe: Why not ... Pinmemberdotnetvirgin9-Aug-06 12:30 
GeneralRe: Why not ... PinmemberMythran14-Aug-06 9:20 
GeneralRe: Why not ... Pinmemberdotnetvirgin15-Aug-06 13:23 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 8 Aug 2006
Article Copyright 2006 by Mythran
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid