Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/workers
Class: Color

require(["esri/Color"], function(Color) { /* code goes here */ });

Description

(Added at v3.9)
Inherits all attributes from dojo/_base/Color to provide functions for setting colors.

See also

Samples

Search for samples that use this class.

Constructors

NameSummary
new Color(color?)Creates a new Color object.

Constants

NameDescription
namedDictionary list of all CSS named colors, by name. Values are 3-item arrays with corresponding RG and B values.

Properties

NameTypeSummary
aNumberThe alpha value.
bNumberThe blue value.
gNumberThe green value.
rNumberThe red value.

Methods

NameReturn typeSummary
blendColors(start, end, weight, obj?)ColorBlend colors start and end with weight from 0 to 1, 0.5 being a 50/50 blend.
fromArray(a, obj?)ColorBuilds a Color from a 3 or 4 element array, mapping each element in sequence to the rgb(a) values of the color.
fromHex(color, obj?)ColorConverts a hex string with a '#' prefix to a color object.
fromRgb(color, obj?)ColorReturns a Color instance from a string of the form "rgb()" or "rgba()".
fromString(str, obj?)ColorParses str for a color value.
setColor(color)ColorTakes a named string, hex string, array of rgb or rgba values, an object with r, g, b, and a properties, or another Color object and sets this color instance to that value.
toCss(includeAlpha?)StringReturns a css color string in rgb(a) representation.
toHex()StringReturns a CSS color string in hexadecimal representation.
toRgb()Number[]Returns a 3 component array of rgb values.
toRgba()Number[]Returns a 4 component array of rgba values.
Constructor Details

new Color(color?)

Creates a new Color object.
Parameters:
<String | Number[] | Object> color Optional A named string, hex string, array of rgb or rgba values, an object with r, g, b, and a properties, or another Color object.
  • Named string: new Color("blue")
  • Hex string: new Color("#C0C0C0")
  • R,G,B: new Color([255,0,0])
  • R,G,B,A. The "A" value represents transparency where 0.0 is fully transparent and 1.0 has no transparency: new Color([255,0,0,0.25])
Property Details

<Number> a

The alpha value.
Known values: 0.0-1.0

<Number> b

The blue value.
Known values: 0-255

<Number> g

The green value.
Known values: 0-255

<Number> r

The red value.
Known values: 0-255
Method Details

blendColors(start, end, weight, obj?)

Blend colors start and end with weight from 0 to 1, 0.5 being a 50/50 blend. Optionally accepts a Color object to update and return instead of creating a new object.

Note: This is a static method.

Return type: Color
Parameters:
<Color> start Required The start color.
<Color> end Required The end color.
<Number> weight Required The weight value.
<Color> obj Optional A previously allocated Color object to reuse for the result.
Sample:
  var startColor = new Color("#0000FF");
  var endColor = new Color("#CA0013");
  var blendedColor = Color.blendColors(startColor, endColor, 0.5);

fromArray(a, obj?)

Builds a Color from a 3 or 4 element array, mapping each element in sequence to the rgb(a) values of the color. Optionally accepts a Color object to update with the color value and return instead of creating a new object.

Note: This is a static method.

Return type: Color
Parameters:
<Number[]> a Required The input array.
<Color> obj Optional A previously allocated Color object to reuse for the result.
Sample:
  var redColor = Color.fromArray([201, 0, 19]);

fromHex(color, obj?)

Converts a hex string with a '#' prefix to a color object. Supports 12-bit #rgb shorthand. Optionally accepts a Color object to update with the parsed value and return instead of creating a new object.

Note: This is a static method.

Return type: Color
Parameters:
<String> color Required The input color.
<Color> obj Optional A previously allocated Color object to reuse for the result.
Sample:
  var redColor = Color.fromHex("#CA0013");

fromRgb(color, obj?)

Returns a Color instance from a string of the form "rgb()" or "rgba()". Optionally accepts a Color object to update with the parsed value and return instead of creating a new object.

Note: This is a static method.

Return type: Color
Parameters:
<String> color Required The input color.
<Color> obj Optional A previously allocated Color object to reuse for the result.
Sample:
  var redColor = Color.fromRgb("rgb(202,0,19)");

fromString(str, obj?)

Parses str for a color value. Accepts hex, rgb, and rgba style color values. Optionally accepts a Color object to update with the parsed value and return instead of creating a new object.

Note: This is a static method.

Acceptable input values for str may include arrays of any form accepted by dojo.colorFromArray, hex strings such as "#aaaaaa", or rgb or rgba strings such as "rgb(133, 200, 16)" or "rgba(10, 10, 10, 50)".
Return type: Color
Parameters:
<String> str Required The input value.
<Color> obj Optional A previously allocated Color object to reuse for the result.
Sample:
  var redColor = Color.fromString("rgb(202,0,19)");

setColor(color)

Takes a named string, hex string, array of rgb or rgba values, an object with r, g, b, and a properties, or another Color object and sets this color instance to that value.
Return type: Color
Parameters:
<String | Number[] | Object> color Required The new color value.

toCss(includeAlpha?)

Returns a css color string in rgb(a) representation.
Return type: String
Parameters:
<Boolean> includeAlpha Optional If true, the alpha value will be included in the result.

toHex()

Returns a CSS color string in hexadecimal representation.
Return type: String

toRgb()

Returns a 3 component array of rgb values.
Return type: Number[]

toRgba()

Returns a 4 component array of rgba values.
Return type: Number[]