In an MFC application.
I'm loading a 32bit PNG file with alpha channel bits into a Gdiplus::Bitmap using FromFile.
I then use Bitmap::GetHBitmap to retrieve an HBITMAP from the Gdiplus::Bitmap.
I use that handle to add the Bitmap to an imagelist.
I use that imagelist to add toolbar buttons to a toolbar.
However, for some odd reason, the image does not use the alpha channel as expected. Instead of using the alpha channel to determine transparency, it uses the a combination of the alpha channel, and how close the pixel's color to White (0x??FFFFFF) to calculate transparency. So an image with progressively transparent white pixels does not show up at all, yet an image with progressively transparent black pixels shows correctly.
I later edited the code to ensure that my Bitmap to HBitmap uses transparent as a background color开发者_C百科, and background color in the imagelist and the toolbar is transparent, and had the same results.
I've also used the HBITMAP to get a CBitmap and premultiplied the bitmapbits using AlphaBlend() method to draw on a window, and this draws correctly.
I've made sure that my image list is using the 32-bit image setting, the ILC_COLOR32 flag.
So I know the issue lies in how the image is added to either the imagelist or the toolbar, but cannot figure out how to correct this.
This is all done dynamically, so I'm not having the same issue that people are complaining about VisualStudio removing the alpha channel.
Issue resolved, it was some incredibly hidden code that was converting whiteness to transparency. It's beyond me why, but there you have it.
feel free to close question.
精彩评论