BitBlt color key

Started by
2 comments, last by kirkd 17 years, 6 months ago
I'm working in Win32 and using BitBlt to copy my bitmaps to a memory DC. This is ultimately copied to the screen. All the bitmaps I'm using have a black background, so when I copy the background gets carried along. The end result is a black rectangle around my sprites. How do I set a color key (for lack of a better term) such that the background doesn't get copied but the colored portions of the bitmap do?? I've dug through a number of BitBlt tutorials as well as MSDN and Petzold, but can't seem to find anything. -Kirk
Advertisement
This may be of interest. I'm not sure there is any simpler way of getting transparency out of BitBlt, although I may be wrong since I don't know much about GDI really.

HTH
What you need to do is create a mask that has white where you want transparency, blit that to the screen with SRCAND, and then after that blit your image (with black as transparency) over top using SRCPAINT (OR).

Here's an article I found on it:

Blt Transparency

Edit: Okay, easily confused beat me to it.

Okay, to try and make myself useful, and since I was also interested in this, I found another article here that explains the same technique, but at the bottom it shows another method that can do it directly by setting a transparent colour in the destination if the device supports it.
Thanks, guys! Wow! 18 minutes to an answer. Nice.

This topic is closed to new replies.

Advertisement