Windows button ignores alpha channel for fully transparent image

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Windows button ignores alpha channel for fully transparent image


BS_AUTORADIOBUTTON|BS_PUSHLIKE|BS_BITMAP


CreateDIBSection


BITMAPINFO


BI_RGB


ppvBits


BM_SETIMAGE



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?





Why would you want to 'display' a completely transparent image?
– Paul Sanders
Aug 6 at 23:20





@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
Aug 7 at 0:26





@IInspectable Well, in this case it would seem that one has no choice.
– Paul Sanders
Aug 7 at 7:09





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
Aug 7 at 16:47



CreateDIBSection


BITMAPV4HEADER


BI_BITFIELDS


ARGB





Another option: use custom draw
– zett42
Aug 7 at 16:54




1 Answer
1



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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS