Image of Navigational Panel mapped to Contents / Home / Search Creating a Transparent Bitmap
Tech Support Question

Image of Line Break

Q. Quick question...is there any way of setting a BMP Image/Picture control so that the background colour is transparent. Basically I am trying to move a couple of images around the screen (of a circular format) without the annoying background colour of the BMP creating a 'frame' for the image.

Is there any native way of doing this (and if so I am just being extremely stupid), or is the only way to use an API function (that I don't know)?

I would appreciate your advice on the matter, as a have seen no topics in any FAQ that cover this.

Thanks,

From: Peter Cox
Email: peter_cox@uk.ibm.com

A. Pete, just maybe I can help you with this one. Don't be concerned this is a difficult thing to do (well, it's not straightforward) so don't be alarmed that it didn't just occur to you. Unfortunately there is no easy way to do this (that I'm aware of). And no simple API call to do it. What you basically have to do is use binary operators to cancel out the required areas of the bitmap using a mask bitmap. It's all very complicated. However, take solace there is help close at hand. If you are using VB3 there is an article in the graphics section of the knowledgebase help file that deals with exactly this topic. The article is Q94961 and can be accessed online via www.microsoft.com/kb. The summary section of the article reads as follows:

Here are the six general steps required to create a transparent bitmap:

  1. Store the area, or background, where the bitmap is going to be drawn.
  2. Create a monochrome mask of the bitmap that identifies the transparent areas of the bitmap by using a white pixel to indicate transparent areas and a black pixel to indicate non-transparent areas of the bitmap.
  3. Combine the pixels of the monochrome mask with the background bitmap using the And binary operator. The area of the background where the non-transparent portion of the bitmap will appear is made black.
  4. Combine an inverted copy of the monochrome mask (step 2) with the source bitmap using the And binary operator. The transparent areas of the source bitmap will be made black.
  5. Combine the modified background (step 3) with the modified source bitmap (step 4) using the Xor binary operator. The background will show through the transparent portions of the bitmap.
  6. Copy the resulting bitmap to the background

The article also includes sample VB3 code to do this.

I hope this helps you out. Good Luck.


Image of Arrow to Previous Article Image of Arrow to Next Article

[TECH SUPPORT TOC]
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]