Available in the LEADTOOLS Imaging toolkit. |
Implementing Transparency
You can implement transparency when doing any of the following:
Animation. When playing an animation, the playback process recognizes the transparent color specified in the BitmapTransparentColor property if the BitmapEnableTransparency property is set to TRUE. The transparent color is loaded from and saved to GIF files. If you save animated files in other multi-page formats, you must maintain the color yourself. For more information, refer to Playing an Animation.
Paint effects. When painting a bitmap or other object, you can specify a transparent color in the BitmapTransparentColor property and set the BitmapEnableTransparency property. For more information about painting images, refer to Displaying an Image. For painting other objects, refer to Drawing Three-Dimensional Shapes and Text.
Displaying an image with transparent color. When painting a bitmap, you can specify a transparent color in the BitmapTransparentColor property and set the BitmapEnableTransparency property to TRUE. LEAD will then paint the bitmap without the color set in the TransparentColor property.
Note: When loading an image file of any supported file format, LEADTOOLS ActiveX control will load the transparent color information into the BitmapTransparentColor property. You must set BitmapEnableTransparency property to TRUE for proper display. For example:
VB Example:
Dim value As Long
Dim Index As Long
'LEAD1.Load “c:\ltwin14x\images\Attention.gif”, 0, 0, 1
value = LEAD1.BitmapTransparentColor
'Account for the COLORREF, which can be a palette index or an RGB value
If value >= 16777216 Then ' Palette index
Index = value - 16777216
LEAD1.BitmapTransparentColor
= LEAD1.BitmapPalette(Index)
Else ' RGB value
LEAD1.BitmapTransparentColor
= value
End If
LEAD1.BitmapEnableTransparency
= True
LEAD1.ForceRepaint
Region processing. Defining a region in a bitmap makes it possible to treat the area outside the region as transparent. You can set the PaintRgnOnly property to TRUE to paint only the region that is defined for a bitmap. When combining images with the Combine method, if a region is defined for the target bitmap, the combine applies only to the region. (Any region defined in the source bitmap is ignored.). For example, if a transparent color is defined for a bitmap, you can create a region that omits pixels of that color. For details, refer to Combining Images.
Once a region is defined, you can create a mask from it, which you can save in the alpha channel of a 16- or 32-bit file. Refer to the BitmapAlpha property for an example of how to save a region in an alpha channel.
Transparent control. You can make the background of the LEAD control transparent by setting the Transparent propertyTransparentproperty to TRUE. This lets you take advantage of related transparency properties when one control is positioned on top of another one.
When specifying a transparent color, you can refer to a particular palette index, instead of the RGB value. This can be useful in cases where a color is used for transparency and the palette may contain the same color in more than one palette position.
When specifying a palette index as a color value, use the following formula:
16777216 + index
When evaluating a value to see if it is a palette index, you can use the following logic:
if value >= 16777216 then
index = value – 16777216