I have a C# DLL that loads a bitmap object from a PNG file. Thanks to Bob
Powell's advice i managed to access the Bitmap data using the lockbits method
and then call the Windows API function CreateBitmap successfully. Then the
DLL provides a COM interface which returns the handle to the bitmap created
using CreateBitmap function.
The problem is that the initial bitmap has a transparent background color,
and when using the CreateBitmap function, the bitmap seems to loose this
color, which is then replaced by black (maybe something to see with
ColorPalette). Furthermore, the createdbitmap is a 32bit bitmap so the alpha
layer which contains transparency informations should be the same. So i don't
know what i missing or doing wrong. here is the code that creates the bitmap
:
Bitmap bitmap = (Bitmap) Bitmap.FromFile(@"C:\tmpicon.png");
BitmapData data = bitmap.LockBits(new Rectangle(new Point(0,0),
bitmap.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
IntPtr HBITMAP = CreateBitmap(bitmap.Width, bitmap.Height, 1, 32, data.Scan0);
NB : I also noticed that when opening the PNG file with MS Paint, the
transparent color is replaced by black, whereas opening it with Photoshop or
Windows Picture viewer, the transparency is visible. Can't explain this...
I'd like to understand what im missing to keep the transparent color on the
created bitmap.
Thx for any help.