Implementing Transparency

You can implement transparency when doing any of the following:

When specifying a transparent color, you can use the Windows PALETTEINDEX macro to refer to a particular palette index (where the COLORREF value is >= 0x01000000). Using a palette index for transparency means that one of the remaining colors in the palette can have the same RGB value as the transparent color, without being interpreted as transparent.

Setting Transparent Colors For Annotation Bitmap Objects (Document/Medical toolkits)

The annotation Stamp object (ANNOBJECT_STAMP, which includes the different Rubber Stamp tools) and Point object (ANNOBJECT_POINT) can be set to display bitmaps that use a transparent color. A transparent color is a color that is not painted when the image is painted. By default the transparent color is white (0x00FFFFFF). Use the following functions to work with transparent colors:

LAnnPoint::GetTransparentColor

LAnnPoint::GetTransparent

LAnnPoint::SetTransparentColor

LAnnPoint::SetTransparent

LAnnStamp::GetTransparentColor

LAnnStamp::GetTransparent

LAnnStamp::SetTransparentColor

LAnnStamp::SetTransparent

LAnnAutomation::GetTransparentColor

LAnnAutomation::SetTransparentColor

LAnnContainer::SetTransparent

 

LBitmapBase::FeatherAlphaBlend is a powerful function that can be used to implement transparency, using a mask. In a many applications, a transparency mask is saved as an alpha channel. If a bitmap contains a transparency mask in the alpha channel, call CreateAlphaBitmap to get the alpha channel information back into a bitmap form. Once the transparency mask information is in a bitmap, it can be passed directly to the LBitmapBase::FeatherAlphaBlend  function as the mask. The following code demonstrates how to do this:

void TestFunction(HWND hWnd)
{
LBitmapWindow Image;
LBitmapBase MaskBitmap,AlphaBitmap,DstBitmap;
int nRet;

Image.SetWndHandle(hWnd);
Image.Load(TEXT("c:\\parrots.jpg"));

/* Specify a rectangle to define the region */
RECT Rect={10,10,50,200};
LBitmapRgn Region(&Image);

// check if the bitmap region is valid or not
if (Region.IsValid() == FALSE)
Region.SetBitmap(&Image) ;

/* Create an elliptical region in the AlphaBitmap */
Region.SetRgnEllipse(&Rect);

/* Create a mask bitmap from the region */
nRet = Region.CreateMaskFromBitmapRgn(&MaskBitmap, sizeof(BITMAPHANDLE)) ;

/* Update the alpha channel in the main bitmap */
Image.SetAlpha(MaskBitmap);

/* Save the bitmap at 16 bits per pixel to keep the alpha channel */
Image.Save(TEXT("c:\\Test.Tif"), FILE_TIF, 16, 0,1, 0);

/* Load the bitmap that we just saved and get its alpha channel */
Image.Load(TEXT("c:\\Test.Tif"));
AlphaBitmap.CreateAlphaBitmap(Image);

DstBitmap.Create(AlphaBitmap.GetWidth(), AlphaBitmap.GetHeight(), 24, ORDER_BGR, NULL, TOP_LEFT, TYPE_CONV);
nRet = DstBitmap.FeatherAlphaBlend(0, 0, AlphaBitmap.GetWidth(), AlphaBitmap.GetHeight(),
&Image, 0, 0, &MaskBitmap);

Image.SetHandle(DstBitmap.GetHandle());
}