BitmapAlpha example for Visual J++

This example shows how to use the BitmapAlpha property to save a region in a file's alpha channel. It also shows how to use the region as a mask for transparency.

LEAD1.Load( "c:\\lead\\images\\image1.cmp", (short) 0, (short) 0, (short) 1 );
LEAD1.setAutoRepaint( false );
// Get an alpha channel bitmap, and fill it with white
LEAD2.setBitmap( LEAD1.getBitmapAlpha() );
LEAD2.Fill( new Color( 255, 255, 255 ) );
int nRgnTop = 0;
int nRgnLeft = 0;
int nRgnWidth = (int) LEAD1.getBitmapWidth();
int nRgnHeight = (int) LEAD1.getBitmapHeight();

// Create an elliptical region in the AlphaBitmap
LEAD2.SetRgnEllipse( nRgnTop, nRgnLeft, nRgnWidth, nRgnHeight, (short) LTOCXU.RgnCombineModeConstants.L_RGN_SET );
// Fill the region with black
LEAD2.Fill( new Color( 0, 0, 0 ) );
// Free the region
LEAD2.FreeRgn();
// Update the alpha channel in the main bitmap
LEAD1.setBitmapAlpha( LEAD2.getBitmap() );
// Save the bitmap as 32-bit TGA
LEAD1.Save( "test.tga", (short) LTOCXU.FileConstants.FILE_TGA, (short) 32, (short) 0, (short) LTOCXU.SaveModifyConstants.SAVE_OVERWRITE );
// Free the bitmaps
LEAD1.setBitmap( 0 );
LEAD2.setBitmap( 0 );

// Load the bitmap we just saved and get the alpha channel
LEAD1.Load( "test.tga", (short) 0, (short) 0, (short) 1 );
LEAD2.setBitmap( LEAD1.getBitmapAlpha() );
// Create a region in the AlphaBitmap that includes all of the black pixels
LEAD2.SetRgnColor( new Color( 0, 0, 0 ), (short) LTOCXU.RgnCombineModeConstants.L_RGN_SET );
// Get the region from the AlphaBitmap and set it into the main bitmap
int hRGN = LEAD2.GetRgnHandle();
LEAD1.SetRgnHandle( hRGN, 0, 0, (short) LTOCXU.RgnCombineModeConstants.L_RGN_SET );
LEAD1.setPaintRgnOnly( true );
LEAD1.ForceRepaint();