开发者

Creating a Transparent Bitmap with GDI?

开发者 https://www.devze.com 2022-12-28 04:49 出处:网络
I want to implement a layering system in my application and was thinking of creating a bunch of transparent bitmaps, adding content to them then blitting 开发者_如何学Pythonthem on top of each other,

I want to implement a layering system in my application and was thinking of creating a bunch of transparent bitmaps, adding content to them then blitting 开发者_如何学Pythonthem on top of each other, how can this be done without setting each pixel to (0,0,0,0). I'm using Pure win32, not MFC, thanks.


What do you mean by transparent?

If you are looking for partial (to full) transparency, then AlphaBlend is the GDI API to use. Loading bitmaps with alpha is tricky - The only format the base windows API supports for loading bitmaps with alpha is a 32bpp .BMP file with an alpha channel in the top 8 bits of each byte - and the lower bytes should to be pre-multiplied.

It is possible to use GDI+ to load a variety of image formats with alpha - PNG is probably the best to go for, and blit onto a 32bpp DIBSection so you can use AlphaBlend and plain-old GDI functions.

If you want a simple transparency mask rather than a full alpha channel you can use TransparentBlt along with a color key to mask out areas of a bitmap when blitting it.


GDI does not support transparency in bitmaps and in general. Consider using GDI+.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号