Example: Alpha Blending

The Blend example demonstrates constant opacity and variable opacity alpha blending with fg_blenddcb() and fg_blendvar(). Its WM_CREATE handler loads two 640x480 BMP files into a high color virtual buffer and calls fg_getdcb() to retrieve each image as a direct color bitmap. The DCB created from CAT.BMP will be the background image, and the DCB created from PORCH.BMP will be the foreground image. The WM_CREATE handler also calls the program's MakeOpacityBitmap() function to create a 256-color opacity bitmap. This bitmap will be created with zero values at its center, and values that gradually increase as we move farther from the center.

Initially Blend will display the foreground image. Pressing F2 displays the background image, and pressing F1 displays the foreground image again. Pressing F3 creates a 50% blended image with fg_blenddcb() and then displays it. Similarly, pressing F4 creates a variable opacity blended image with fg_blendvar(), using the opacity bitmap created by MakeOpacityBitmap(), and then displays the blended image. The two blended images are shown here:

The opacity values are zero in the center of the variable blended image and increase outward. This means the foreground is completely transparent in the middle, but completely opaque around the edges. Hence the background image (that is, the cat) dominates the center part of the blended image, but the foreground image (the porch) is prevalent most everywhere else.

C/C++ version

C++Builder version

Delphi version

Visual Basic version

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.