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.
By "selecting" a bitmap into a memory DC, the DC then represents that bitmap as a drawing surface, and all the normal GDI operations can be performed on the bitmap.
Sometimes we need to draw objects on top of images- and these objects may need to be transparent. As we discussed earlier, color in GDI+ has four components: alpha, red, green, and blue. The value of each component varies from 0 to 255. The alpha component represents the transparency in GDI+ color.
Will make white (255,255,255) transparent on any bitmap you use this image attribute with. The simplest solution is to use some format other than BMP. You need the bits to contain alpha data, and you need the Bitmap to be in a format that has alpha data.
When you load a BMP with GDI+, it will always use a format without alpha, even if the BMP has an alpha channel. I believe the data is there in the image bits, but it's not being used.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With