COLORKEY property (Image)

Description

Specifies the color in the image that is considered to be the "transparent color".

 

Property Value

This property can be a standard RGB color value or one of the special "color-key" values listed below:

 

Value Description
-1 Top-Left pixel contains the color to use for the color-key.
-2 Top-Right pixel contains the color to use for the color-key
-3 Bottom-Left pixel contains the color to use for the color-key.
-4 Bottom-Right pixel contains the color to use for the color-key.
-5 No Color-Key (this is the default value)

 

 

Property Traits

Development

Runtime

Indexed

Scaled

Synthetic

Get/Set

Get/Set

No

No

No

 

Remarks

Earlier versions of OpenInsight have supported basic image transparency via a method called “color-keying”, where a specific color in the image is nominated as the transparent color (by default the color of the top-left pixel).  When the image is drawn to screen the pixels that match the transparent color are not rendered so the background pixels show through instead.  Whilst this can be effective in simple cases, it is sub-optimal for images that have smooth curves and shadows as these tend to appear very pixelated.

 

A much better alternative is to use an image format that supports an “alpha channel” such as a PNG file. Basically this means that each pixel in the image has an extra byte that describes its transparency - a value of 0 means that the pixel is totally transparent, while a value of 255 means that the pixel is totally opaque, Values in between are used to calculate how the image pixel is combined with the background pixel when drawn, so that it gives the appearance of being translucent, allowing the background pixel to show through to some degree.  This is a technique known as Alpha-blending and is supported fully in this version of OpenInsight.

 

Because of this you should only use color-keying on older format images like 24-bit bitmap images that do not have an alpha channel - using a more modern formats like PNG files will give much better results.

 

Equated constants for the COLORKEY property can be found in the PS_EQUATES insert record with the prefix "PS_TC_".

 

Example

The 24-bit bitmap image below (i.e.no alpha-channel) has a white background.  To draw it "transparently" onto a surface that is a different color we have to set the COLORKEY property.  In this case we can hard-code it to White (RGB value of 0x00FFFFFF), or we can tell it to use one of the corner pixels instead.

 

 

Example

   $Insert PS_Equates

   

   * // Example 1: Set the ColorKey of the background image for the

   * // current window to use the top-left pixel of the image.

   

   Call Set_Property_Only( @Window : ".IMAGE", "COLORKEY", PS_TC_TOPLEFT$ )  

 

The code above gives the following results:

 

 

Note the pixelated edge due to the shadow in the image. A PNG file with an alpha-channel gives much better results however, as the shadow is blended correctly:

 

 

See Also

N/A