DADiSP Worksheet Functions > Function Categories > Colors > RGBTOCOLOR

 

RGBTOCOLOR

Purpose:

Returns the color index of the RGB values.

Syntax:

RGBTOCOLOR(r, g, b)

r

-

A real. The value of the red component for the color (0.0 <= r <= 1.0).

g

-

A real. The value of the green component for the color (0.0 <= g <= 1.0).

b

-

A real. The value of the blue component for the color (0.0 <= b <= 1.0).

 

Alternate Syntax:

RGBTOCOLOR(rgbvalue)

rgbvalue

-

An integer. The RGB palette value.

Returns:

An integer, the color index if successful, else -1.

Example:

cindex = rgbtocolor(1, 1, 0);

 

cindex == 14

strcolor(cindex) == "YELLOW"

 

Returns the color index for the color YELLOW given the individual RGB components.

 

cindex = rgbtocolor(0x00FFFF)

 

produces the same result.

Example:

cindex1 = defcolor("Money", 0.753, 0.863, 0.750);

cindex2 = rgbtocolor(0.753, 0.863, 0.750);

 

cindex1 == cindex2

 

strcolor(cindex2) == "Money"

 

Defines a new color named Money where RGBTOCOLOR returns the same color index as DEFCOLOR.

Remarks:

RGBTOCOLOR also accepts RGB integer values between 0 and 255. For example:

 

defcolor("DodgerBlue", 30, 144, 255)

strcolor(rgbtocolor(30, 144, 255)) == "DodgerBlue"

 

To use this form, each RGB value must be an integer between 0 and 255.

 

See COLORTORGB to return RGB values from a color index.

 

See COLORSTR to convert a color name into a color index.

 

See STRCOLOR to convert a color index into a color name.

 

See RGBIMAGE to create an image from RGB values.

 

See WEBCOLORS to define a set of web compatible colors.

See Also:

COLORSTR

COLORTORGB

DEFCOLOR

RGBIMAGE

STRCOLOR

WEBCOLORS