Color class

Color class

The Color class lets you specify colors as Red-Green-Blue (RGB) values, Hue-Saturation-Luminosity (HSL) values, Hue-Saturation-Value (HSV) values, Hue-Whiteness-Blackness (HWB) values, lightness-A-B (LAB) values, Luminance-Chroma-Hue (LCH) values, Cyan-Magenta-Yellow-Key (CMYK) values, Natural colors (NCOL) values, or with a color name. An Alpha channel is also available to indicate transparency.

The Color type exposes the following members:

Constructors

ConstructorDescription
initInitializes a new instance of the Color class.
By default color is black.
initInitializes a new instance of the Color class.
All color components must be in the range 0-1.
initInitializes a new instance of the Color class.
All color components must be in the range 0-1.
initInitializes a new instance of the Color class.
All color components must be in the range 0-255.
initInitializes a new instance of the Color class.
All color components must be in the range 0-255.
initInitializes a new instance of the Color class.
All color components must be in the range 0-255.
initInitializes a new instance of the Color class.
All color components must be in the range 0-255.

Properties

PropertyDescription
redRepresents the red component of the color
greenRepresents the green component of the color.
blueRepresents the blue component of the color.
alphaRepresents the alpha component of the color.

Methods

MethodDescription
from_rgbReturns a new Color with the requested ged, green, blue values.
All color components must be in the range 0-255.
from_rgbReturns a new Color with the requested ged, green, blue values.
All color components must be in the range 0-255.
from_rgbReturns a new Color with the requested ged, green, blue values.
All color components must be in the range 0-1.
from_rgbaReturns a new Color with the requested ged, green, blue, alpha values.
All color components must be in the range 0-255.
from_rgbaReturns a new Color with the requested ged, green, blue, alpha values.
All color components must be in the range 0-255.
from_rgbaReturns a new Color with the requested ged, green, blue, alpha values.
All color components must be in the range 0-1.
from_grayReturns a new Color with the requested gray value.
from_uintReturns a new Color with the requested ARGB value.
from_intReturns a new Color with the requested ARGB value.
from_stringParses string containing the CSS color and returns a new Color.
from_hslReturns a new Color with the requested hue, saturation, saturation values.
from_hslaReturns a new Color with the requested hue, saturation, saturation, alpha values.
from_hsvReturns a new Color with the requested hue, saturation, value.
from_hsvaReturns a new Color with the requested hue, saturation, value, alpha.
from_hwbReturns a new Color with the requested hue, whiteness, blackness values.
from_hwbaReturns a new Color with the requested hue, whiteness, blackness values.
from_cmykReturns a new Color with the requested cyan, magenta, yellow, key (black) values.
from_cmykaReturns a new Color with the requested cyan, magenta, yellow, key (black), alpha values.
from_labReturns a new Color with the requested lightness, A, B values.
from_labaReturns a new Color with the requested lightness, A, B, alpha values.
from_oklabReturns a new Color with the requested lightness, A, B values for OKLAB model.
from_oklabaReturns a new Color with the requested lightness, A, B, alpha values for OKLAB model.
from_lchReturns a new Color with the requested luminance, chroma, hue values.
from_lchaReturns a new Color with the requested luminance, chroma, hue, alpha values.
from_oklchReturns a new Color with the requested luminance, chroma, hue values for OKLAB model.
from_oklchaReturns a new Color with the requested luminance, chroma, hue, alpha values for OKLAB model.
to_rgb_hex_stringReturns a hexadecimal color is specified with: #RRGGBB.
to_natural_color_stringReturns a Natural colors (NCol) specified color using a color letter with a number to specify the distance (in percent) from the color.
to_nameReturns the name of the color if it matches a color in the list of CSS named colors, or an empty string.
convertReturns a color components in the format of the specified color model.
to_rgb_stringReturns a string containing the RGB color specified by: rgb(R, G, B).
to_rgba_hex_stringReturns a Hexadecimal color is specified with: #RRGGBBAA.
to_rgba_stringReturns a string containing the RGBA color specified by: rgba(R, G, B, A).
to_intEncodes the Color ARGB components into int.
to_uintEncodes the Color ARGB components into unsigned int.
get_luminosityReturns a luminosity of the Color.
add_luminosityCreates copy of the Color with Sum of its luminosity and the delta value.
with_luminosityCreates copy of the Color with specified luminosity.
with_alphaCreates copy of the Color with specified alpha component.
get_saturationReturns a saturation of the Color.
with_saturationCreates copy of the Color with specified saturation.
get_hueReturns a Hue of the Color.
with_hueCreates copy of the Color with specified Hue.
get_complementaryReturns a new color that is on the opposite side of the color wheel from the original.

See Also