Question

I have a BMP file which I know is 32bpp and contains alpha information. Whenever I use the System.Drawing.Bitmap class's constructor, or FromFile, it loads it as 32bppRgb instead of 32bppArgb. Is there a way to keep the alpha information? I know BMP is a simple file format for which I could write my own loader, but I would rather not. It seems like there should be an option somewhere.

Was it helpful?

Solution

Unfortunately, GDI+ does not support alpha channels in BMP files. Here's the relevant note in the docs:

The Image class does not support alpha transparency in bitmaps. To enable alpha transparency, use PNG images with 32 bits per pixel.

Your best bet is to either convert the file to a format that supports transparency (like PNG) in a separate program that supports BMP alpha, or write your own code to do it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top