Skip to content
CShift0.45

Color

Struct · namespace System.Drawing · Since 0.45

struct Color : IEquatable<Color>, IHashable

A 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(); // 0xFFFF0000
var same = Color.FromArgb(argb);
var sky = Color.FromRgb(0x87CEEBu); // 0xRRGGBB, as in CSS
Name Description
A Alpha: 0 is transparent, 255 opaque.
R Red.
G Green.
B Blue.
uint8 A

Alpha: 0 is transparent, 255 opaque.

uint8 R

Red.

uint8 G

Green.

uint8 B

Blue.

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.
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).

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).

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.

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.

static Color DarkGray()

Dark gray, #404040.

static Color LightGray()

Light gray, #C0C0C0.

static Color Red()

Red, #FF0000.

static Color Green()

Green, #00FF00.

static Color Blue()

Blue, #0000FF.

static Color Yellow()

Yellow, #FFFF00.

static Color Cyan()

Cyan, #00FFFF.

static Color Magenta()

Magenta, #FF00FF.

static Color Orange()

Orange, #FFA500.

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.
uint32 ToArgb()

The color as a 32-bit value 0xAARRGGBB.

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.

bool IsOpaque()

Whether the alpha is 255.

bool IsTransparent()

Whether the alpha is 0.

bool Equals(Color other)

Whether all four components are the same.

int GetHashCode()

A hash code (the ARGB value).

string ToString()

The color as text: #AARRGGBB.