Conversion
The Color Pro package supports converting colors to and from 20+ color models. Every supported type has its own data structure (except Hex). The Conversion class declares functions to convert between different types, but in most cases this class does not need to be used directly. Extension methods exist on colors to convert between types, see below.
Generic Conversion
Colors can be converted using generic type constraints. Any of the color models specified on this page can be used. For example:
RGB rgb = color.To<RGB>();
HSV hsv = color.To<HSV>();
CMYK cmyk = color.To<CMYK>();
Additionally, any color model can be converted to any other color model.
RGB rgb = color.To<RGB>();
HSV hsv = rgb.To<HSV>();
CMYK cmyk = hsv.To<CMYK>();
Some color models have direct conversions to other color models. When possible, it is better to use the direct conversion methods rather than the generic ones.
RGB rgb = color.ToRGB();
HSV hsv = rgb.ToHSV();
HSL hsl = hsv.ToHSL();
CIEXYZ xyz = rgb.ToXYZ();
CIELAB lab = xyz.ToLAB();
See the Scripting API for more detailed usage. All available color models are listed below.
ARGB
The ARGB (alpha, red, green, blue) components of a color in the range [0..1].
ARGB argb = color.ToARGB();
Color color = argb.ToColor();
ARGB255
The ARGB (alpha, red, green, blue) components of a color in the range [0..255].
ARGB255 argb = color.ToARGB255();
Color color = argb.ToColor();
CIE LAB
The CIE LAB components of a color - lightness (L) and chromaticity (a,b).
CIELAB lab = color.ToLab();
Color color = lab.ToColor();
CIE LUV
The CIE LUV components of a color - lightness (L) and chromaticity (u,v).
CIELUV luv = color.ToLuv();
Color color = luv.ToColor();
CIE LCh(ab)
The CIE LCh(ab) components of a color - lightness (L), chroma (C), and hue (h).
CIELCh_ab lch = color.ToLCh_ab();
Color color = lch.ToColor();
CIE LCh(uv)
The CIE LCh(uv) components of a color - lightness (L), chroma (C), and hue (h).
CIELCh_uv lch = color.ToLCh_uv();
Color color = lch.ToColor();
CIE UCS
The CIE UCS components of a color - (u,v) chromaticity coordinates.
CIEUCS ucs = color.ToUCS();
Color color = ucs.ToColor();
CIE UVW
The CIE UVW components of a color - chromaticity (U,V) and lightness (W).
CIEUVW uvw = color.ToUVW();
Color color = uvw.ToColor();
CIE xyY
The CIE xyY components of a color - chromaticity (x,y) and luminance (Y).
CIExyY xyY = color.ToxyY();
Color color = xyY.ToColor();
CIE XYZ
The CIE XYZ components of a color - chromaticity (X,Z) and luminance (Y).
CIEXYZ xyz = color.ToXYZ();
Color color = xyz.ToColor();
CMYK
The CMYK (cyan, magenta, yellow, black) components of a color in the range [0..1].
CMYK cmyk = color.ToCMYK();
Color color = cmyk.ToColor();
Hex
Hexadecimal colors are represented as strings "#ff0000" or integers 0xff0000. Colors can be converted using RGB, RGBA, and ARGB formats which determine the order of the bits.
int hex = color.ToHex();
int hex_rgba = color.ToHexRGBA();
int hex_argb = color.ToHexARGB();
string hex = color.ToHexString();
string hex_rgba = color.ToHexStringRGBA();
string hex_argb = color.ToHexStringARGB();
Color color = Hex.ToColor(hex);
Color color = Hex.ToRGBAColor(hex_rgba);
Color color = Hex.ToARGBColor(hex_argb);
HSB
The HSB (hue, saturation, brightness) components of a color in the range [0..1].
HSB components = color.ToHSB();
Color color = components.ToColor();
HSI
The HSI (hue, saturation, intensity) components of a color in the range [0..1].
HSI components = color.ToHSI();
Color color = components.ToColor();
HSL
The HSL (hue, saturation, lightness) components of a color in the range [0..1].
HSL components = color.ToHSL();
Color color = components.ToColor();
HSV
The HSV (hue, saturation, value) components of a color in the range [0..1].
HSV components = color.ToHSV();
Color color = components.ToColor();
Hunter Lab
The Hunter Lab components of a color - lightness (L) and chromaticity (a,b).
HunterLab components = color.ToHunterLab();
Color color = components.ToColor();
LMS
The LMS (long, medium, short) components of a color.
LMS components = color.ToLMS();
Color color = components.ToColor();
RGB
The RGB (red, green, blue) components of a color in the range [0..1].
RGB components = color.ToRGB();
Color color = components.ToColor();
RGB255
The RGB (red, green, blue) components of a color in the range [0..255].
RGB255 components = color.ToRGB255();
Color color = components.ToColor();
RGBA
The RGBA (red, green, blue, alpha) components of a color in the range [0..1].
RGBA components = color.ToRGBA();
Color color = components.ToColor();
RGBA255
The RGBA (red, green, blue, alpha) components of a color in the range [0..255].
RGBA255 components = color.ToRGBA255();
Color color = components.ToColor();
YCbCr
The Y′CbCr components of a color - luma (Y′) and chroma (Cb,Cr).
YCbCr components = color.ToYCbCr();
Color color = components.ToColor();
YPbPr
The Y′PbPr components of a color - luma (Y′) and chroma (Pb,Pr).
YPbPr components = color.ToYPbPr();
Color color = components.ToColor();
YIQ
The Y′IQ components of a color - luma (Y′) and chroma (I,Q).
YIQ components = color.ToYIQ();
Color color = components.ToColor();
YUV
The Y′UV components of a color - luma (Y′) and chroma (U,V).
YUV components = color.ToYUV();
Color color = components.ToColor();