BitmapAlpha example for Access 2.0

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.

Dim rgntop As Single
Dim rgnleft As Single
Dim rgnwidth As Single
Dim rgnheight As Single
Dim hRGN As Long

Me![LEAD1].Object.ScaleMode = 3
Me![LEAD1].Object.Load "c:\lead\images\image1.cmp", 0, 0, 1
Me![LEAD1].Object.AutoRepaint = False

'Get an alpha channel bitmap, and fill it with white
Me![LEAD2].Object.Bitmap = Me![LEAD1].Object.BitmapAlpha
Me![LEAD2].Object.Fill RGB(255, 255, 255)

rgntop = 0
rgnleft = 0
rgnwidth = Me![LEAD1].Object.BitmapWidth
rgnheight = Me![LEAD1].Object.BitmapHeight

'Create an elliptical region in the AlphaBitmap
Me![LEAD2].Object.SetRgnEllipse rgntop, rgnleft, rgnwidth, rgnheight, L_RGN_SET

'Fill the region with black
Me![LEAD2].Object.Fill RGB(0, 0, 0)

'Free the region
Me![LEAD2].Object.FreeRgn

'Update the alpha channel in the main bitmap
Me![LEAD1].Object.BitmapAlpha = Me![LEAD2].Object.Bitmap

'Save the bitmap as 32-bit TGA
Me![LEAD1].Object.Save "test.tga", FILE_TGA, 32, 0, SAVE_OVERWRITE

'Free the bitmaps
Me![LEAD1].Object.Bitmap = 0
Me![LEAD2].Object.Bitmap = 0

'Load the bitmap we just saved and get the alpha channel
Me![LEAD1].Object.Load "test.tga", 0, 0, 1
Me![LEAD2].Object.Bitmap = Me![LEAD1].Object.BitmapAlpha

'Create a region in the AlphaBitmap that includes all of the black pixels
Me![LEAD2].Object.SetRgnColor RGB(0, 0, 0), L_RGN_SET

'Get the region from the AlphaBitmap and set it into the main bitmap
hRGN = Me![LEAD2].Object.GetRgnHandle
Me![LEAD1].Object.SetRgnHandle hRGN, 0, 0, L_RGN_SET

Me![LEAD1].Object.PaintRgnOnly = True
Me![LEAD1].Object.ForceRepaint