RGB
From Xojo Documentation
This item was deprecated in version 2019r2. Please use Color.RGB as a replacement. |
Returns a Color based on the red, green, blue, and alpha values specified. You can also specify a color using the HSV or CMY function or the &c color constant, &cRRGGBB or &cRRGGBBAA. Use the new form of the Picture constructor to create pictures that support the alpha channel or convert existing pictures to the new format using the code described in HasAlphaChannel.
Syntax
result=RGB(red, green, blue, [alpha = 0])
Part | Type | Description |
---|---|---|
result | Color | An object that represents the color based on the red, green, blue, and alpha values. |
red | Integer | The amount of red in the color (0-255). |
green | Integer | The amount of green in the color (0-255). |
blue | Integer | The amount of blue in the color (0-255). |
alpha | 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). |
Transparency
The following example draws sample color patches in a Canvas with varying levels of transparency. With the RGB function, the range is from 0 to 255. Zero is completely opaque and 255 is completely transparent. The code is in the Paint event.
g.DrawRect(0, 0, 200, 50)
g.FillRect(0, 0, 200, 50)
g.ForeColor = RGB(0, 0, 0) // black text
g.DrawString("Translucent = 0", 210, 10)
g.ForeColor = RGB(255, 0, 0, 77) // transparency = .3
g.FillRect(0, 70, 200, 50)
g.ForeColor = RGB(0, 0, 0, 0)
g.DrawString("Translucent = 30%", 210, 80)
g.ForeColor = RGB(255, 0, 0, 127) // transparency = .5
g.FillRect(0, 140, 200, 50)
g.ForeColor = RGB(0, 0, 0)
g.DrawString("Translucent = 50%", 210, 150)
g.ForeColor = RGB(255, 0, 0, 179) // transparency = .7
g.FillRect(0, 210, 200, 50)
g.ForeColor = RGB(0, 0, 0)
g.DrawString("Translucent = 70%", 210, 220)
g.ForeColor = RGB(255, 0, 0, 229) // transparency = .9
g.FillRect(0, 280, 200, 50)
g.ForeColor = RGB(0, 0, 0)
g.DrawString("Translucent = 90%", 210, 290)
The result is shown here.
Notes
The RGB 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 RGB model using the &c literal. With the &c literal, you specify the amounts of red, green, blue, and transparency in hexadecimal rather than decimal.
Examples
This example uses the RGB function to assign various colors and levels of transparency to the ForeColor property of a Canvas control. The code is in the Paint event.
g.ForeColor = RGB(255, 0, 0, 0) // set to red
g.ForeColor = 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 or a Window.
g.DrawRect(0, 0, 200, 50)
g.FillRect(0, 0, 200, 50)
g.ForeColor = RGB(0, 0, 0)
g.DrawString("Translucent = 0", 210, 10)
g.ForeColor = RGB(255, 0, 0, 100) // transparency = 100
g.FillRect(0, 70, 200, 50)
g.ForeColor = RGB(0, 0, 0, 0)
g.DrawString("Translucent = 100", 210, 80)
g.ForeColor = RGB(255, 0, 0, 200) // transparency = 200
g.FillRect(0, 140, 200, 50)
g.ForeColor = RGB(0, 0, 0, 0)
g.DrawString("Translucent = 200", 210, 150)
See Also
Color data type; CMY, HSV, SelectColor functions; &c literal.