Transparent GIF using Bitmap.Save()

G

Guest

When I create a System.Drawing.Bitmap and save it as ImageType.GIF, how can I
set the transparency so that the background is transparent.

In my application, the Bitmap that I am working with has several transparent
GIFs drawn on it and the transparency of each of them works within the
bitmap, but the bitmap overall gets saved with a black background.

Any help is greatly appreciated.
 
C

Cryptik

In .NET v2 you should be able to do the following:

//Load an Image
Bitmap img = new Bitmap("c:\\image3.bmp");

//Get the color of the first pixel and make that color transparent
Color c = img.GetPixel(0, 0);
img.MakeTransparent(c);

then just save the image...

Kelly S. Elias
Webmaster
DevDistrict - C# Code Library
http://devdistrict.com

Thanks, Bela! That's exactly what I need.

I had read a Microsoft KB article on the same topic, KB #319061, but that
was so confusing I couldn't make head nor tails of it.

Thanks to you and to Bob Powell!
 
K

Kevin Yu [MSFT]

Hi Kelly,

Just for clarification, the MakeTransparent method is not only supported in
..NET framework 2.0, but also 1.1 and 1.0.

http://msdn2.microsoft.com/en-us/library/8517ckds.aspx

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Thanks for the suggestion. I would like to try MakeTransparent in the
future. I couldn't use it in this case because the Graphics object was
corrupting the palette by duplicating the transparent color in the palette.
That meant I still had to create a new image, add my corrected palette, and
then do a pixel by pixel copy to move the original pixels into the new image
as suggested in Bob Powell's article in order to fix issues caused by that
duplicate palette entry.

I sure wish I could have gotten away with something as simple as
MakeTransparent.

Thanks again, Cryptik and Kevin.

Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top