RGB function

Purpose

Create an RGB color value from 3 primary color values or from a BGR value.

Syntax

result& = RGB(red&, green&, blue&)
result&
= RGB(bgrexpr&)

Remarks

An RGB value is a long integer value in the range of 0 to &H00FFFFFF. It is used to specify a very 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 1 (lowest) represents the red component, byte 2 the green, and byte 3 the blue.  They can each take on a value in the range of 0 to 255.  Byte 4 (highest) is always 0.  When used with 3 parameters, the RGB() function creates an RGB value from the three component values.

Some Windows API functions, namely 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.

When used with one parameter, this function translates a BGR value to its RGB equivalent by swapping the first byte with the third byte, and returning the result.

For example, the BGR value of red is &HFF0000.  RGB() translates it to &H0000FF.  Calling BGR() with that value converts it back to &HFF0000.

See also

Built In RGB Color Equates, BGR