Last updated

API / geotoolkit / util / RgbaColor / RgbaColor

Class: RgbaColor

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.

Table of contents

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

Contents

Constructors

new RgbaColor()

new RgbaColor()


new RgbaColor(color)

new RgbaColor(color)

Parameters

Name Type Description
colorstring | RgbaColorready-to-use color (string, rgbacolor...)

new RgbaColor(red, green, blue, alpha)

new RgbaColor(red, green, blue, alpha?)

Parameters

Name Type Description
rednumberred component from 0 to 255
greennumbergreen component from 0 to 255
bluenumberblue component from 0 to 255
Optional alphanumberalpha component from 0 to 255
Methods

clone

clone(): RgbaColor

Return clone of the color

Returns

RgbaColor

clone


equalsTo

equalsTo(other): boolean

Returns true if colors are identical

Parameters

Name Type Description
otherRgbaColorRgbaColor to compare against

Returns

boolean


getAlpha

getAlpha(): number

Return the alpha component value.
The value should be in range[0-255]

Returns

number


getBlue

getBlue(): number

Return the blue component value.
The value should be in range[0-255]

Returns

number


getClassName

getClassName(): string

Returns

string


getGreen

getGreen(): number

Return the green component value.
The value should be in range[0-255]

Returns

number


getRed

getRed(): number

Return the red component value.
The value should be in range[0-255]

Returns

number


setAlpha

setAlpha(val): RgbaColor

Sets the alpha component to the given value.
This function expects the alpha component to be in range[0-1].

Parameters

Name Type Description
valnumbervalue of the alpha component

Returns

RgbaColor

this


setBlue

setBlue(val): RgbaColor

Sets the blue component to the given value.
This function expects the blue component to be in range[0-255].

Parameters

Name Type Description
valnumbervalue of the blue component

Returns

RgbaColor

this


setColor

setColor(red, green, blue, alpha?): RgbaColor

set color value

Parameters

Name Type Description
rednumberred component from 0 to 255
greennumbergreen component from 0 to 255
bluenumberblue component from 0 to 255
Optional alphanumberalpha component from 0 to 255

Returns

RgbaColor

setColor(color): RgbaColor

set color value

Parameters

Name Type Description
colorstring | RgbaColorred component from 0 to 255 or CSS color as a string

Returns

RgbaColor

setColor(red?, green?, blue?, alpha?): RgbaColor

Parameters

Name Type
Optional redstring | number | RgbaColor
Optional greennumber
Optional bluenumber
Optional alphanumber

Returns

RgbaColor


setGreen

setGreen(val): RgbaColor

Sets the green component to the given value.
This function expects the green component to be in range[0-255].

Parameters

Name Type Description
valnumbervalue of the green component

Returns

RgbaColor

this


setRed

setRed(val): RgbaColor

Sets the red component to the given value.
This function expects the red component to be in range[0-255].

Parameters

Name Type Description
valnumbervalue of the red component

Returns

RgbaColor

this


toCSS

toCSS(): string

Return this color in CSS rgba() string format, ex: 'rgba(255, 120, 0, 1.0)'

Returns

string


toGrayScale

toGrayScale(a?, r?, g?, b?): string

Convert this RGBA color to the grayscale color.

Parameters

Name Type Description
Optional anumberChange alpa channel to specified value if any
Optional rnumberr weight default is 0.3
Optional gnumberg weight default is 0.59
Optional bnumberb weight default is 0.11

Returns

string

Resulted color in CSS rgba() string format.


toHex

toHex(a?): string

Convert this RGBA color to the string hexadecimal format, ex: Red -> '#ff0000'.
Alpha channel is not included by default.

Parameters

Name Type Description
Optional abooleanInclude alpha channel in the hexadecimal output, false by default.

Returns

string

Resulted color in hexadecimal


toRgb

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)

Parameters

Name Type Description
Optional backgroundstring | RgbaColorConversion will be based on this background color, default is white.

Returns

string

Resulted color in CSS rgba() string format.


toRgbaString

toRgbaString(): string

Return this color in CSS rgba() string format, ex: 'rgba(255, 120, 0, 1.0)'

Returns

string


fromObject

Static fromObject(object): RgbaColor

Create or get RGBA color from object

Parameters

Name Type Description
objectstring | RgbaColorobject can be in format of constructor of RgbaColor

Returns

RgbaColor


getClassName

Static getClassName(): string

Returns

string