BGR function  

Purpose

Convert an RGB color value to BGR format.

Syntax

bgrColor& = BGR(rgbColor&)

Remarks

An RGB value is a long integer value in the range of 0 to &H00FFFFFF.  It is used to specify a precise color to various PowerBASIC functions and Windows API functions.  The lowest three bytes of the value each specify the intensity of a primary color which combine to form the resultant color.  Byte 0 (lowest) represents the red component, byte 1 the green, and byte 2 the blue.  They can each take on a value in the range of 0 to 255.  Byte 3 (highest) is always 0.  The RGB function can be used to easily create an RGB value from the three component values.

Some Windows API functions, such as those which reference Device Independent Bitmaps (DIB), require that the colors be specified in the reverse sequence (Blue-Green-Red instead of Red-Green-Blue).  In order to maximize performance and execution speed, PowerBASIC statements and functions which reference these structures also use the BGR format. These include GRAPHIC GET BITS and  GRAPHIC SET BITS.

The BGR function translates an RGB value to its BGR equivalent by swapping the first and third bytes and returning the result.  Because of the nature of the translation, calling BGR a second time converts a BGR value back to its original RGB format.

For example, the RGB value of red is &H0000FF.  BGR translates it to &HFF0000.  Calling it a second time converts the value back to H0000FF..

See also

RGB