<div class="meta" robots="noindex">

</div>

Method

# RGB

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `Color.RGB<color.rgb>` as a replacement.

</div>

## Description

Returns a `Color</api/data_types/color>` based on the red, green, blue, and alpha values specified. You can also specify a color using the `Color.HSV<color.hsv>` or `Color.CMY<color.cmy>` function or the `&c</api/language/literals/c>` color constant, `` &c</api/language/literals/c>`RRGGBB or :doc: ``&c\</api/language/literals/c\><span class="title-ref">RRGGBBAA. Use the new form of the :doc:\`Picture\</api/graphics/picture\></span> constructor to create pictures that support the alpha channel or convert existing pictures to the new format using the code described in `HasAlphaChannel<picture.hasalphachannel>`.

## Usage

*result*=**RGB**(*red*, *green*, *blue*, \[*alpha* = 0\])

| Part   | Type                               | Description                                                                                                                           |
|--------|------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| result | `Color</api/data_types/color>`     | An object that represents the color based on the *red*, *green*, *blue*, and **alpha** values.                                        |
| red    | `Integer</api/data_types/integer>` | The amount of red in the color (0-255).                                                                                               |
| green  | `Integer</api/data_types/integer>` | The amount of green in the color (0-255).                                                                                             |
| blue   | `Integer</api/data_types/integer>` | The amount of blue in the color (0-255).                                                                                              |
| alpha  | `Integer</api/data_types/integer>` | The amount of translucency of the color (0 - 255 ). The value of zero is opaque and 255 is transparent. The default is zero (opaque). |

## Notes

The <span class="title-ref">RGB</span> function returns a color object based on the amounts of red, green, blue, and transparency passed. These amounts are represented by integers between 0 and 255.

You can also specify a color using the <span class="title-ref">RGB</span> model using the `&c</api/language/literals/c>` literal. With the `&c</api/language/literals/c>` literal, you specify the amounts of red, green, blue, and transparency in hexadecimal rather than decimal.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Transparency

The following example draws sample color patches in a `Canvas</api/deprecated/canvas>` with varying levels of transparency. With the <span class="title-ref">RGB</span> function, the range is from 0 to 255. Zero is completely opaque and 255 is completely transparent. The code is in the `Paint<canvas.paint>` event.

``` xojo
g.ForeColor =Color.RGB(255, 0, 0, 0)  ' red color patch, no transparency
g.DrawRect(0, 0, 200, 50)

g.FillRect(0, 0, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0) ' black text
g.DrawString("Translucent = 0", 210, 10)

g.ForeColor =Color.RGB(255, 0, 0, 77) ' transparency = .3

g.FillRect(0, 70, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0, 0)
g.DrawString("Translucent = 30%", 210, 80)

g.ForeColor =Color.RGB(255, 0, 0, 127) ' transparency = .5

g.FillRect(0, 140, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0)
g.DrawString("Translucent = 50%", 210, 150)

g.ForeColor =Color.RGB(255, 0, 0, 179) ' transparency = .7

g.FillRect(0, 210, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0)
g.DrawString("Translucent = 70%", 210, 220)

g.ForeColor =Color.RGB(255, 0, 0, 229) ' transparency = .9

g.FillRect(0, 280, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0)
g.DrawString("Translucent = 90%", 210, 290)
```

The result is shown here.

> ![image](images/rgb_translucentpatches.jpg)

## Sample code

This example uses the <span class="title-ref">RGB</span> function to assign various colors and levels of transparency to the ForeColor property of a `Canvas</api/deprecated/canvas>` control. The code is in the Paint event.

``` xojo
g.ForeColor =Color.RGB(0, 0, 0, 0) ' set to black
g.ForeColor =Color.RGB(255, 0, 0, 0) ' set to red
g.ForeColor =Color.RGB(255, 255, 255, 0) ' set to white
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This example draws three red rectangles with varying levels of transparency. The code is in the Paint event of a `Canvas</api/deprecated/canvas>` or a `Window</api/deprecated/window>`.

``` xojo
g.ForeColor =Color.RGB(255, 0, 0, 0)
g.DrawRect(0, 0, 200, 50)

g.FillRect(0, 0, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0)
g.DrawString("Translucent = 0", 210, 10)

g.ForeColor =Color.RGB(255, 0, 0, 100) ' transparency = 100

g.FillRect(0, 70, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0, 0)
g.DrawString("Translucent = 100", 210, 80)

g.ForeColor =Color.RGB(255, 0, 0, 200) ' transparency = 200

g.FillRect(0, 140, 200, 50)
g.ForeColor =Color.RGB(0, 0, 0, 0)
g.DrawString("Translucent = 200", 210, 150)
```

## Compatibility

All project types on all supported operating systems.

## See also

`Color</api/data_types/color>` data type; `Color.CMY<color.cmy>`, `Color.HSV<color.hsv>`, `Color.SelectedFromDialog<color.selectedfromdialog>` functions; `&c</api/language/literals/c>` literal.
