views:

263

answers:

2

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 them 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.

A: 

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

Kirill V. Lyadvinsky
It sortof does - it has support for transparent blending of one bitmap onto another, using alpha components in the bitmap through AlphaBlend. There are also the odd extensions to support Aero in windows that might count too. You're right about the general case though.
David M
There's also TransparentBlt, but when using 32 bit images (e.g. those with transparency specified) AlphaBlend is the way to go.
dlanod
+4  A: 

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.

Chris Becke