Xbasic

BITMAP_ALPHA Function

Syntax

V BITMAP_ALPHA(C bitmap_name,N XPos,N YPos,C level_bitmap)

Arguments

bitmap_nameCharacter

The name of the bitmap to modify.

XPosNumeric

The horizontal coordinate of the upper left corner of the bitmap.

YPosNumeric

The vertical coordinate of the upper left corner of the bitmap.

level_bitmapCharacter

The name of the bitmap to use as the alpha channel. A pixel value of 0 is completely transparent. A pixel value of 255 is completely opaque. Intermediate values represent degrees of transparency.

Description

Draws a bitmap using a different bitmap an alpha-value.

Discussion

BITMAP_ALPHA() sets the transparency of each of the pixels in a bitmap according to the values of the corresponding pixels in an alpha channel bitmap, then draws the result.

Example

Get the original color image, then extract the color data and the alpha channel data.

png_data = file.to_blob("c:\documents\Xbasic Reference\Images\toucan.png")
rgb_data = png_to_bitmap(png_data, "R")
trans_data = png_to_bitmap(png_data, "A")

Create two bitmaps from the color data and the alpha channel data.

ui_bitmap_load("rgb", rgb_data)
ui_bitmap_load("trans", trans_data)

Calculate the positions of the three images.

pixsize = ui_bitmap_info_get(rgb_data, "w,h")
xpix = val( word(pixsize, 1, ",") )
ypix = val( word(pixsize, 2, ",") )
xperin = ui_info(4)
yperin = ui_info(5)
width = xpix/xperin
height = ypix/yperin

Combine the three images.

ui_bitmap_create("combine", width, height)
stone_data = file.to_blob("C:\WINDOWS\Greenstone.bmp")
ui_bitmap_load("Stone", stone_data)
ui_bitmap_draw("combine", <<%code%
bitmap("stone", 0, 0)
bitmap_alpha("rgb", 0, 0, "trans")
%code%)

Display the three images.

images/GR_bitmap_alpha.gif
ui_dlg_box("image", <<%dlg% {image=rgb} {image=trans} {image=combine}
%dlg%)

Limitations

Used only in the Code sections of UI_BITMAP_DRAW(), UI_SCREEN_DRAW(), and UI_PRINTER_DRAW().

See Also