0
votes
  • I have a radio button that should display an image (style BS_AUTORADIOBUTTON|BS_PUSHLIKE|BS_BITMAP).
  • I create a bitmap via CreateDIBSection (using a BITMAPINFO with BI_RGB) and obtain a pointer to the raw pixels via the ppvBits, so that I can manipulate them freely.
  • I use BM_SETIMAGE to set the button's image to the bitmap I created.

So far, I can set the RGB and alpha by manipulating the pixels by hand. I tested that even semi-transparent (non-premultiplied) alpha values look good.

As far as I can tell, everything works, except if all pixels in the image are transparent. In that case, the button apparently ignores the alpha value, simply displaying a rectangle with each pixel having the respective color with full opacity.

I found a hint that Windows - at least in some cases - actually seems to interpret images whose pixels' alpha values are all 0 as completely opaque images:

When the window manager sees a 32bpp bitmap, it looks at the alpha channel. If it's all zeroes, then it assumes that the image is in 0RGB format; otherwise it assumes it is in ARGB format

Is this behavior documented somewhere?

1
Why would you want to 'display' a completely transparent image?Paul Sanders
@PaulSanders: To serve as a placeholder, for example. Or simply because it's easier to not write code, that tries to analyze an image prior to deciding, whether it should be displayed. Less code to write, less chance of introducing bugs, and - most importantly - less code to read.IInspectable
@IInspectable Well, in this case it would seem that one has no choice.Paul Sanders
In the call to CreateDIBSection, try to use BITMAPV4HEADER with BI_BITFIELDS to specify the alpha mask. This could allow the system to determine that the bitmap actually is in ARGB format, without using heuristics. If that doesn't work, a workaround could be to set the top-left pixel alpha value to 1, which I bet nobody will notice.zett42
Another option: use custom drawzett42

1 Answers

1
votes

Is this behaviour documented somewhere?

Yes! In Raymond's post! :) That's often the way of it, no?

If you look at the foot of the page here you will find a comments box. If you raise your concerns there then MS will most likely fix their documentation. See here for an example of the process they usually follow if they consider the problem serious enough to fix.