API / geotoolkit / util / RgbaColor / RgbaColor
Specify RGBA color, which can be defined as a set of the four color components (Red, Green, Blue, Alpha). Each component must be from 0 to 255.
Constructors
| [new RgbaColor()](/solutions/geotoolkit/apis/classes/geotoolkit.util.rgbacolor.rgbacolor.md#new rgbacolor()) | [new RgbaColor(color)](/solutions/geotoolkit/apis/classes/geotoolkit.util.rgbacolor.rgbacolor.md#new rgbacolor(color)) | [new RgbaColor(red, green, blue, alpha)](/solutions/geotoolkit/apis/classes/geotoolkit.util.rgbacolor.rgbacolor.md#new rgbacolor(red, green, blue, alpha)) |
|---|
Methods
Constructors
• new RgbaColor()
• new RgbaColor(color)
| Name | Type | Description |
|---|---|---|
color | string | RgbaColor | ready-to-use color (string, rgbacolor...) |
• new RgbaColor(red, green, blue, alpha?)
| Name | Type | Description |
|---|---|---|
red | number | red component from 0 to 255 |
green | number | green component from 0 to 255 |
blue | number | blue component from 0 to 255 |
Optional alpha | number | alpha component from 0 to 255 |
Methods
▸ clone(): RgbaColor
Return clone of the color
clone
▸ equalsTo(other): boolean
Returns true if colors are identical
| Name | Type | Description |
|---|---|---|
other | RgbaColor | RgbaColor to compare against |
boolean
▸ getAlpha(): number
Return the alpha component value.
The value should be in range[0-255]
number
▸ getBlue(): number
Return the blue component value.
The value should be in range[0-255]
number
▸ getClassName(): string
string
▸ getGreen(): number
Return the green component value.
The value should be in range[0-255]
number
▸ getRed(): number
Return the red component value.
The value should be in range[0-255]
number
▸ setAlpha(val): RgbaColor
Sets the alpha component to the given value.
This function expects the alpha component to be in range[0-1].
| Name | Type | Description |
|---|---|---|
val | number | value of the alpha component |
this
▸ setBlue(val): RgbaColor
Sets the blue component to the given value.
This function expects the blue component to be in range[0-255].
| Name | Type | Description |
|---|---|---|
val | number | value of the blue component |
this
▸ setColor(red, green, blue, alpha?): RgbaColor
set color value
| Name | Type | Description |
|---|---|---|
red | number | red component from 0 to 255 |
green | number | green component from 0 to 255 |
blue | number | blue component from 0 to 255 |
Optional alpha | number | alpha component from 0 to 255 |
▸ setColor(color): RgbaColor
set color value
| Name | Type | Description |
|---|---|---|
color | string | RgbaColor | red component from 0 to 255 or CSS color as a string |
▸ setColor(red?, green?, blue?, alpha?): RgbaColor
| Name | Type |
|---|---|
Optional red | string | number | RgbaColor |
Optional green | number |
Optional blue | number |
Optional alpha | number |
▸ setGreen(val): RgbaColor
Sets the green component to the given value.
This function expects the green component to be in range[0-255].
| Name | Type | Description |
|---|---|---|
val | number | value of the green component |
this
▸ setRed(val): RgbaColor
Sets the red component to the given value.
This function expects the red component to be in range[0-255].
| Name | Type | Description |
|---|---|---|
val | number | value of the red component |
this
▸ toCSS(): string
Return this color in CSS rgba() string format, ex: 'rgba(255, 120, 0, 1.0)'
string
▸ toGrayScale(a?, r?, g?, b?): string
Convert this RGBA color to the grayscale color.
| Name | Type | Description |
|---|---|---|
Optional a | number | Change alpa channel to specified value if any |
Optional r | number | r weight default is 0.3 |
Optional g | number | g weight default is 0.59 |
Optional b | number | b weight default is 0.11 |
string
Resulted color in CSS rgba() string format.
▸ toHex(a?): string
Convert this RGBA color to the string hexadecimal format, ex: Red -> '#ff0000'.
Alpha channel is not included by default.
| Name | Type | Description |
|---|---|---|
Optional a | boolean | Include alpha channel in the hexadecimal output, false by default. |
string
Resulted color in hexadecimal
▸ toRgb(background?): string
Convert this RGBA color to RGB, by pre-multiplying alpha and colors, and compositing with the background color.
By default, the background color is white. For ex:
- 50% opacity White - rgba(255, 255, 255, 0.5) on a black background will become Grey - rgba(127, 127, 127, 1.0)
- 50% opacity Red - rgba(255, 0, 0, 0.5) on a white background will become Pink - rgba(255, 127, 127, 1.0)
| Name | Type | Description |
|---|---|---|
Optional background | string | RgbaColor | Conversion will be based on this background color, default is white. |
string
Resulted color in CSS rgba() string format.
▸ toRgbaString(): string
Return this color in CSS rgba() string format, ex: 'rgba(255, 120, 0, 1.0)'
string
▸ Static fromObject(object): RgbaColor
Create or get RGBA color from object
| Name | Type | Description |
|---|---|---|
object | string | RgbaColor | object can be in format of constructor of RgbaColor |
▸ Static getClassName(): string
string