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.
Asked
Active
Viewed 1,326 times
4
-
This is somewhat related. Perhaps it will help you http://stackoverflow.com/questions/10658994/using-graphics-drawimage-to-draw-image-with-transparency-alpha-channel – Eric J. Feb 20 '14 at 23:56
-
1Loading bmps with alpha channels doesn't appear to be supported. See this thread: http://social.msdn.microsoft.com/Forums/vstudio/en-US/2f81979d-30f0-4a41-9c5e-ff49c28ab814/loading-image-from-32-bits-bitmap-file?forum=csharpgeneral. – 500 - Internal Server Error Feb 21 '14 at 00:04
-
1You can not load.bmp formats supporting alpha. – γηράσκω δ' αεί πολλά διδασκόμε Feb 21 '14 at 01:12
-
It supports alpha for PNG files - are you constrained to using only BMP, or do you have the potential to switch formats? – Baldrick Feb 21 '14 at 01:40
-
Thank you for the replies. I had read the GIF transparency article before posting. The other article was quite enlightening. I am not constrained to BMP, I was trying to support both PNG and BMP. I have put BMP support on hold until I can load them manually. Thanks for the help. – nor Feb 27 '14 at 18:41
1 Answers
0
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.

izrik
- 918
- 2
- 9
- 20