Color
Struct · namespace System.Drawing · Since 0.45
struct Color : IEquatable<Color>, IHashableA color: alpha, red, green and blue, from 0 to 255 each (an alpha of 0 is transparent, 255 opaque).
var red = Color.FromRgb(255, 0, 0);uint32 argb = red.ToArgb(); // 0xFFFF0000var same = Color.FromArgb(argb);var sky = Color.FromRgb(0x87CEEBu); // 0xRRGGBB, as in CSSFields
Section titled “Fields”| Name | Description |
|---|---|
A |
Alpha: 0 is transparent, 255 opaque. |
R |
Red. |
G |
Green. |
B |
Blue. |
uint8 AAlpha: 0 is transparent, 255 opaque.
uint8 RRed.
uint8 GGreen.
uint8 BBlue.
Static methods
Section titled “Static methods”| Name | Description |
|---|---|
FromArgb |
A color from its four components (0 to 255 each). |
FromRgb |
An opaque color from red, green and blue (0 to 255 each). |
FromHsv |
An opaque color from hue (degrees, 0 red, 120 green, 240 blue; any value, it wraps around), saturation and value (0.0 to 1.0 each; clamped). |
Transparent |
Transparent white, 0x00FFFFFF (like Color.Transparent of .NET; Image.Create fills with transparent black, 0). |
Black |
Opaque black. |
White |
Opaque white. |
Gray |
Gray, #808080. |
DarkGray |
Dark gray, #404040. |
LightGray |
Light gray, #C0C0C0. |
Red |
Red, #FF0000. |
Green |
Green, #00FF00. |
Blue |
Blue, #0000FF. |
Yellow |
Yellow, #FFFF00. |
Cyan |
Cyan, #00FFFF. |
Magenta |
Magenta, #FF00FF. |
Orange |
Orange, #FFA500. |
FromArgb
Section titled “FromArgb”static Color FromArgb(int alpha, int red, int green, int blue)A color from its four components (0 to 255 each).
Panics when a component is not 0 to 255.
static Color FromArgb(uint32 argb)A color from a 32-bit value 0xAARRGGBB (the value of Color.ToArgb and of Image.Pixels).
FromRgb
Section titled “FromRgb”static Color FromRgb(int red, int green, int blue)An opaque color from red, green and blue (0 to 255 each).
Panics when a component is not 0 to 255.
static Color FromRgb(uint32 rgb)An opaque color from a 24-bit value 0xRRGGBB (the notation of CSS and of paint programs).
FromHsv
Section titled “FromHsv”static Color FromHsv(double hue, double saturation, double value)An opaque color from hue (degrees, 0 red, 120 green, 240 blue; any value, it wraps around), saturation and value (0.0 to 1.0 each; clamped). Useful for rainbows and for colors that change smoothly.
Transparent
Section titled “Transparent”static Color Transparent()Transparent white, 0x00FFFFFF (like Color.Transparent of .NET; Image.Create fills with transparent
black, 0).
static Color Black()Opaque black.
static Color White()Opaque white.
static Color Gray()Gray, #808080.
DarkGray
Section titled “DarkGray”static Color DarkGray()Dark gray, #404040.
LightGray
Section titled “LightGray”static Color LightGray()Light gray, #C0C0C0.
static Color Red()Red, #FF0000.
static Color Green()Green, #00FF00.
static Color Blue()Blue, #0000FF.
Yellow
Section titled “Yellow”static Color Yellow()Yellow, #FFFF00.
static Color Cyan()Cyan, #00FFFF.
Magenta
Section titled “Magenta”static Color Magenta()Magenta, #FF00FF.
Orange
Section titled “Orange”static Color Orange()Orange, #FFA500.
Methods
Section titled “Methods”| Name | Description |
|---|---|
ToArgb |
The color as a 32-bit value 0xAARRGGBB. |
WithAlpha |
The same color with another alpha (0 to 255; clamped). |
Lerp |
The color between this one (t = 0.0) and other (t = 1.0; clamped), all four components mixed. |
Scale |
Red, green and blue multiplied by factor (below 1.0 darker, above brighter; each clamped to 255), the same alpha. |
Over |
This color painted over background with its alpha (“source over”): what a canvas does with a pixel. |
IsOpaque |
Whether the alpha is 255. |
IsTransparent |
Whether the alpha is 0. |
Equals |
Whether all four components are the same. |
GetHashCode |
A hash code (the ARGB value). |
ToString |
The color as text: #AARRGGBB. |
ToArgb
Section titled “ToArgb”uint32 ToArgb()The color as a 32-bit value 0xAARRGGBB.
WithAlpha
Section titled “WithAlpha”Color WithAlpha(int alpha)The same color with another alpha (0 to 255; clamped).
Color Lerp(Color other, double t)The color between this one (t = 0.0) and other (t = 1.0; clamped), all four components mixed.
Color Scale(double factor)Red, green and blue multiplied by factor (below 1.0 darker, above brighter; each clamped to 255), the same
alpha.
Color Over(Color background)This color painted over background with its alpha (“source over”): what a canvas does with a pixel.
IsOpaque
Section titled “IsOpaque”bool IsOpaque()Whether the alpha is 255.
IsTransparent
Section titled “IsTransparent”bool IsTransparent()Whether the alpha is 0.
Equals
Section titled “Equals”bool Equals(Color other)Whether all four components are the same.
GetHashCode
Section titled “GetHashCode”int GetHashCode()A hash code (the ARGB value).
ToString
Section titled “ToString”string ToString()The color as text: #AARRGGBB.