Why the Bitmap.MakeTransparent() changes the PixelFormat ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Experts,

I'm creating a bitmap object like this:
Bitmap myImage = new Bitmap(1024, 1024,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);

But when I invoking the function myImage .MakeTransparent() (with or without
parameters), the myImage.PixelFormat changes to Format32bppArgb.

Why is that and how can I avoid it but still making the Bitmap transparent ?
 
The 24bpp pixel format doesn't define transparency (Alpha) and so the system
automatically changes to a format that can express the transparent value.

There is no way to display a 24bpp image with transparency on a per-pixel
basis.

--
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.
 
Hi Sharon,
Generally speaking, 24bit only includes RGB (three colors), not include
alpha value. So it can't produce transparent effect. I think this is the
reason when invoking the function MakeTransparent(), the PixelFormat
changes to Format32bppArgb. Because it will need alpha value(8 bits) to
generate transparent effect.


Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
 
Back
Top