BitmapAlpha example for C++ Builder
void __fastcall TForm1::AlphaRGNClick(TObject *Sender)
{
int rgntop ;
int rgnleft ;
int rgnwidth ;
int rgnheight ;
HRGN hRGN ;
int test;
LEADImage1->Load ("v:\\images\\image1.cmp", 0, 0, 1);
LEADImage1->AutoRepaint = False;
/*Get an alpha channel bitmap, and fill it with white*/
LEADImage2->Bitmap = LEADImage1->BitmapAlpha;
LEADImage2->SetRgnColor (RGB(0, 0, 0), L_RGN_SETNOT);
test= LEADImage2->GetRgnArea ();
//test here is test = 0, then Alpha is all black
if (test == 0)
ShowMessage ("Alpha image is all black");
LEADImage2->Fill (RGB(255, 255, 255));
rgntop = 0;
rgnleft = 0;
rgnwidth = LEADImage1->BitmapWidth;
rgnheight = LEADImage1->BitmapHeight;
/*Create an elliptical region in the AlphaBitmap*/
LEADImage2->SetRgnEllipse (rgntop, rgnleft, rgnwidth, rgnheight, L_RGN_SET);
/*Fill the region with black*/
LEADImage2->Fill (RGB(0, 0, 0));
/*Free the region*/
LEADImage2->FreeRgn ();
/*Update the alpha channel in the main bitmap*/
LEADImage1->BitmapAlpha = LEADImage2->Bitmap;
/*Save the bitmap as 32-bit TGA*/
LEADImage1->Save ("test.tga", FILE_TGA, 32, 0, SAVE_OVERWRITE);
/*Free the bitmaps*/
LEADImage1->Bitmap = 0;
LEADImage2->Bitmap = 0;
/*Load the bitmap we just saved and get the alpha channel*/
LEADImage1->Load ("test.tga", 0, 0, 1);
LEADImage2->Bitmap = LEADImage1->BitmapAlpha;
/*Create a region in the AlphaBitmap that includes all of the black pixels*/
LEADImage2->SetRgnColor (RGB(0, 0, 0), L_RGN_SET);
/*get the region from the AlphaBitmap and set it into the main bitmap*/
hRGN = (HRGN)LEADImage2->GetRgnHandle ();
LEADImage1->SetRgnHandle ((int)hRGN, 0, 0, L_RGN_SET);
LEADImage1->PaintRgnOnly = True;
LEADImage1->ForceRepaint ();
}