all groups > dotnet drawing api > april 2006 >
You're in the

dotnet drawing api

group:

Bitmap.MakeTrasnparent makes background black when saving from clipboard


Bitmap.MakeTrasnparent makes background black when saving from clipboard BIG_j
4/27/2006 12:00:00 AM
dotnet drawing api:
I have dynamic image(s) on the clipboard that I need to save as a
transparent gif. There are a number of posts regarding MakeTransparent but I
cannot get this to work for what I am trying to do. I am NOT loading the
picture into a form and there are no paint events to consider. All images
have a white background.

I am simply loading the image from the clipboard and saving it to a file.
Anyone have a solution or workaround??


Here is the code snippet...


Bitmap Img = new Bitmap((Bitmap)Data.GetData(DataFormats.Bitmap, true));

//makes bg black
//Img.MakeTransparent(System.Drawing.Color.FromArgb(255,255,255));

//makes bg black, even though 1,1 is white
//Img.MakeTransparent(Img.GetPixel(1,1));

//makes bg black
//Img.MakeTransparent();

Img.Save("C:\\testImage.gif", System.Drawing.Imaging.ImageFormat.Gif);



Re: Bitmap.MakeTrasnparent makes background black when saving from clipboard Bob Powell [MVP]
4/27/2006 12:59:55 PM
Saving a file as a bitmap will destroy any transparency because the file
format is 24 bits per pixel.

Saving as a PNG will preserve the transparency.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



[quoted text, click to view]

AddThis Social Bookmark Button