Struct Color
An RGBA colour, with each channel a byte from 0 to 255. An alpha of 255 is opaque.
public readonly struct Color : IEquatable<Color>
- Implements
- Inherited Members
Constructors
Color(Color, byte)
Creates a colour with the red, green and blue of color and the alpha a.
public Color(Color color, byte a)
Parameters
Color(Color, float)
Creates a colour with the red, green and blue of color and the alpha a, from 0 to 1,
clamped and rounded as the float constructor's are.
public Color(Color color, float a)
Parameters
Color(byte, byte, byte, byte)
Creates a colour from its channels. a is opaque when not given.
public Color(byte r, byte g, byte b, byte a = 255)
Parameters
Color(int, int, int, int)
Creates a colour from its channels, each from 0 to 255. Each value is cast to a byte without a range check, so a value outside that range wraps around.
public Color(int r, int g, int b, int a = 255)
Parameters
Color(float, float, float, float)
Creates a colour from channels from 0 to 1, where 1 is 255. Each value is clamped to 0 to 1 and rounded to the nearest byte, so a channel brightened past 1 stays at 255.
public Color(float r, float g, float b, float a = 1)
Parameters
Properties
A
The alpha channel, from 0 (transparent) to 255 (opaque).
public byte A { get; }
Property Value
AliceBlue
The named colour #F0F8FF.
public static Color AliceBlue { get; }
Property Value
AntiqueWhite
The named colour #FAEBD7.
public static Color AntiqueWhite { get; }
Property Value
Aqua
The named colour #00FFFF.
public static Color Aqua { get; }
Property Value
Aquamarine
The named colour #7FFFD4.
public static Color Aquamarine { get; }
Property Value
Azure
The named colour #F0FFFF.
public static Color Azure { get; }
Property Value
B
The blue channel, from 0 to 255.
public byte B { get; }
Property Value
Beige
The named colour #F5F5DC.
public static Color Beige { get; }
Property Value
Bisque
The named colour #FFE4C4.
public static Color Bisque { get; }
Property Value
Black
The named colour #000000.
public static Color Black { get; }
Property Value
BlanchedAlmond
The named colour #FFEBCD.
public static Color BlanchedAlmond { get; }
Property Value
Blue
The named colour #0000FF.
public static Color Blue { get; }
Property Value
BlueViolet
The named colour #8A2BE2.
public static Color BlueViolet { get; }
Property Value
Brown
The named colour #A52A2A.
public static Color Brown { get; }
Property Value
BurlyWood
The named colour #DEB887.
public static Color BurlyWood { get; }
Property Value
CadetBlue
The named colour #5F9EA0.
public static Color CadetBlue { get; }
Property Value
Chartreuse
The named colour #7FFF00.
public static Color Chartreuse { get; }
Property Value
Chocolate
The named colour #D2691E.
public static Color Chocolate { get; }
Property Value
Coral
The named colour #FF7F50.
public static Color Coral { get; }
Property Value
CornflowerBlue
The named colour #6495ED.
public static Color CornflowerBlue { get; }
Property Value
Cornsilk
The named colour #FFF8DC.
public static Color Cornsilk { get; }
Property Value
Crimson
The named colour #DC143C.
public static Color Crimson { get; }
Property Value
Cyan
The named colour #00FFFF.
public static Color Cyan { get; }
Property Value
DarkBlue
The named colour #00008B.
public static Color DarkBlue { get; }
Property Value
DarkCyan
The named colour #008B8B.
public static Color DarkCyan { get; }
Property Value
DarkGoldenrod
The named colour #B8860B.
public static Color DarkGoldenrod { get; }
Property Value
DarkGray
The named colour #A9A9A9.
public static Color DarkGray { get; }
Property Value
DarkGreen
The named colour #006400.
public static Color DarkGreen { get; }
Property Value
DarkKhaki
The named colour #BDB76B.
public static Color DarkKhaki { get; }
Property Value
DarkMagenta
The named colour #8B008B.
public static Color DarkMagenta { get; }
Property Value
DarkOliveGreen
The named colour #556B2F.
public static Color DarkOliveGreen { get; }
Property Value
DarkOrange
The named colour #FF8C00.
public static Color DarkOrange { get; }
Property Value
DarkOrchid
The named colour #9932CC.
public static Color DarkOrchid { get; }
Property Value
DarkRed
The named colour #8B0000.
public static Color DarkRed { get; }
Property Value
DarkSalmon
The named colour #E9967A.
public static Color DarkSalmon { get; }
Property Value
DarkSeaGreen
The named colour #8FBC8F.
public static Color DarkSeaGreen { get; }
Property Value
DarkSlateBlue
The named colour #483D8B.
public static Color DarkSlateBlue { get; }
Property Value
DarkSlateGray
The named colour #2F4F4F.
public static Color DarkSlateGray { get; }
Property Value
DarkTurquoise
The named colour #00CED1.
public static Color DarkTurquoise { get; }
Property Value
DarkViolet
The named colour #9400D3.
public static Color DarkViolet { get; }
Property Value
DeepPink
The named colour #FF1493.
public static Color DeepPink { get; }
Property Value
DeepSkyBlue
The named colour #00BFFF.
public static Color DeepSkyBlue { get; }
Property Value
DimGray
The named colour #696969.
public static Color DimGray { get; }
Property Value
DodgerBlue
The named colour #1E90FF.
public static Color DodgerBlue { get; }
Property Value
Firebrick
The named colour #B22222.
public static Color Firebrick { get; }
Property Value
FloralWhite
The named colour #FFFAF0.
public static Color FloralWhite { get; }
Property Value
ForestGreen
The named colour #228B22.
public static Color ForestGreen { get; }
Property Value
Fuchsia
The named colour #FF00FF.
public static Color Fuchsia { get; }
Property Value
G
The green channel, from 0 to 255.
public byte G { get; }
Property Value
Gainsboro
The named colour #DCDCDC.
public static Color Gainsboro { get; }
Property Value
GhostWhite
The named colour #F8F8FF.
public static Color GhostWhite { get; }
Property Value
Gold
The named colour #FFD700.
public static Color Gold { get; }
Property Value
Goldenrod
The named colour #DAA520.
public static Color Goldenrod { get; }
Property Value
Gray
The named colour #808080.
public static Color Gray { get; }
Property Value
Green
The named colour #008000.
public static Color Green { get; }
Property Value
GreenYellow
The named colour #ADFF2F.
public static Color GreenYellow { get; }
Property Value
Honeydew
The named colour #F0FFF0.
public static Color Honeydew { get; }
Property Value
HotPink
The named colour #FF69B4.
public static Color HotPink { get; }
Property Value
IndianRed
The named colour #CD5C5C.
public static Color IndianRed { get; }
Property Value
Indigo
The named colour #4B0082.
public static Color Indigo { get; }
Property Value
Ivory
The named colour #FFFFF0.
public static Color Ivory { get; }
Property Value
Khaki
The named colour #F0E68C.
public static Color Khaki { get; }
Property Value
Lavender
The named colour #E6E6FA.
public static Color Lavender { get; }
Property Value
LavenderBlush
The named colour #FFF0F5.
public static Color LavenderBlush { get; }
Property Value
LawnGreen
The named colour #7CFC00.
public static Color LawnGreen { get; }
Property Value
LemonChiffon
The named colour #FFFACD.
public static Color LemonChiffon { get; }
Property Value
LightBlue
The named colour #ADD8E6.
public static Color LightBlue { get; }
Property Value
LightCoral
The named colour #F08080.
public static Color LightCoral { get; }
Property Value
LightCyan
The named colour #E0FFFF.
public static Color LightCyan { get; }
Property Value
LightGoldenrodYellow
The named colour #FAFAD2.
public static Color LightGoldenrodYellow { get; }
Property Value
LightGray
The named colour #D3D3D3.
public static Color LightGray { get; }
Property Value
LightGreen
The named colour #90EE90.
public static Color LightGreen { get; }
Property Value
LightPink
The named colour #FFB6C1.
public static Color LightPink { get; }
Property Value
LightSalmon
The named colour #FFA07A.
public static Color LightSalmon { get; }
Property Value
LightSeaGreen
The named colour #20B2AA.
public static Color LightSeaGreen { get; }
Property Value
LightSkyBlue
The named colour #87CEFA.
public static Color LightSkyBlue { get; }
Property Value
LightSlateGray
The named colour #778899.
public static Color LightSlateGray { get; }
Property Value
LightSteelBlue
The named colour #B0C4DE.
public static Color LightSteelBlue { get; }
Property Value
LightYellow
The named colour #FFFFE0.
public static Color LightYellow { get; }
Property Value
Lime
The named colour #00FF00.
public static Color Lime { get; }
Property Value
LimeGreen
The named colour #32CD32.
public static Color LimeGreen { get; }
Property Value
Linen
The named colour #FAF0E6.
public static Color Linen { get; }
Property Value
Magenta
The named colour #FF00FF.
public static Color Magenta { get; }
Property Value
Maroon
The named colour #800000.
public static Color Maroon { get; }
Property Value
MediumAquamarine
The named colour #66CDAA.
public static Color MediumAquamarine { get; }
Property Value
MediumBlue
The named colour #0000CD.
public static Color MediumBlue { get; }
Property Value
MediumOrchid
The named colour #BA55D3.
public static Color MediumOrchid { get; }
Property Value
MediumPurple
The named colour #9370DB.
public static Color MediumPurple { get; }
Property Value
MediumSeaGreen
The named colour #3CB371.
public static Color MediumSeaGreen { get; }
Property Value
MediumSlateBlue
The named colour #7B68EE.
public static Color MediumSlateBlue { get; }
Property Value
MediumSpringGreen
The named colour #00FA9A.
public static Color MediumSpringGreen { get; }
Property Value
MediumTurquoise
The named colour #48D1CC.
public static Color MediumTurquoise { get; }
Property Value
MediumVioletRed
The named colour #C71585.
public static Color MediumVioletRed { get; }
Property Value
MidnightBlue
The named colour #191970.
public static Color MidnightBlue { get; }
Property Value
MintCream
The named colour #F5FFFA.
public static Color MintCream { get; }
Property Value
MistyRose
The named colour #FFE4E1.
public static Color MistyRose { get; }
Property Value
Moccasin
The named colour #FFE4B5.
public static Color Moccasin { get; }
Property Value
NavajoWhite
The named colour #FFDEAD.
public static Color NavajoWhite { get; }
Property Value
Navy
The named colour #000080.
public static Color Navy { get; }
Property Value
OldLace
The named colour #FDF5E6.
public static Color OldLace { get; }
Property Value
Olive
The named colour #808000.
public static Color Olive { get; }
Property Value
OliveDrab
The named colour #6B8E23.
public static Color OliveDrab { get; }
Property Value
Orange
The named colour #FFA500.
public static Color Orange { get; }
Property Value
OrangeRed
The named colour #FF4500.
public static Color OrangeRed { get; }
Property Value
Orchid
The named colour #DA70D6.
public static Color Orchid { get; }
Property Value
PaleGoldenrod
The named colour #EEE8AA.
public static Color PaleGoldenrod { get; }
Property Value
PaleGreen
The named colour #98FB98.
public static Color PaleGreen { get; }
Property Value
PaleTurquoise
The named colour #AFEEEE.
public static Color PaleTurquoise { get; }
Property Value
PaleVioletRed
The named colour #DB7093.
public static Color PaleVioletRed { get; }
Property Value
PapayaWhip
The named colour #FFEFD5.
public static Color PapayaWhip { get; }
Property Value
PeachPuff
The named colour #FFDAB9.
public static Color PeachPuff { get; }
Property Value
Peru
The named colour #CD853F.
public static Color Peru { get; }
Property Value
Pink
The named colour #FFC0CB.
public static Color Pink { get; }
Property Value
Plum
The named colour #DDA0DD.
public static Color Plum { get; }
Property Value
PowderBlue
The named colour #B0E0E6.
public static Color PowderBlue { get; }
Property Value
Purple
The named colour #800080.
public static Color Purple { get; }
Property Value
R
The red channel, from 0 to 255.
public byte R { get; }
Property Value
Red
The named colour #FF0000.
public static Color Red { get; }
Property Value
RosyBrown
The named colour #BC8F8F.
public static Color RosyBrown { get; }
Property Value
RoyalBlue
The named colour #4169E1.
public static Color RoyalBlue { get; }
Property Value
SaddleBrown
The named colour #8B4513.
public static Color SaddleBrown { get; }
Property Value
Salmon
The named colour #FA8072.
public static Color Salmon { get; }
Property Value
SandyBrown
The named colour #F4A460.
public static Color SandyBrown { get; }
Property Value
SeaGreen
The named colour #2E8B57.
public static Color SeaGreen { get; }
Property Value
SeaShell
The named colour #FFF5EE.
public static Color SeaShell { get; }
Property Value
Sienna
The named colour #A0522D.
public static Color Sienna { get; }
Property Value
Silver
The named colour #C0C0C0.
public static Color Silver { get; }
Property Value
SkyBlue
The named colour #87CEEB.
public static Color SkyBlue { get; }
Property Value
SlateBlue
The named colour #6A5ACD.
public static Color SlateBlue { get; }
Property Value
SlateGray
The named colour #708090.
public static Color SlateGray { get; }
Property Value
Snow
The named colour #FFFAFA.
public static Color Snow { get; }
Property Value
SpringGreen
The named colour #00FF7F.
public static Color SpringGreen { get; }
Property Value
SteelBlue
The named colour #4682B4.
public static Color SteelBlue { get; }
Property Value
Tan
The named colour #D2B48C.
public static Color Tan { get; }
Property Value
Teal
The named colour #008080.
public static Color Teal { get; }
Property Value
Thistle
The named colour #D8BFD8.
public static Color Thistle { get; }
Property Value
Tomato
The named colour #FF6347.
public static Color Tomato { get; }
Property Value
Transparent
Fully transparent black, with no colour of its own.
public static Color Transparent { get; }
Property Value
Turquoise
The named colour #40E0D0.
public static Color Turquoise { get; }
Property Value
Violet
The named colour #EE82EE.
public static Color Violet { get; }
Property Value
Wheat
The named colour #F5DEB3.
public static Color Wheat { get; }
Property Value
White
The named colour #FFFFFF.
public static Color White { get; }
Property Value
WhiteSmoke
The named colour #F5F5F5.
public static Color WhiteSmoke { get; }
Property Value
Yellow
The named colour #FFFF00.
public static Color Yellow { get; }
Property Value
YellowGreen
The named colour #9ACD32.
public static Color YellowGreen { get; }
Property Value
Methods
Equals(Color)
Whether all four channels equal those of other.
public bool Equals(Color other)
Parameters
otherColor
Returns
Equals(object)
Whether obj is a Color with the same channels.
public override bool Equals(object obj)
Parameters
objobject
Returns
FromArgb(byte, byte, byte, byte)
Creates a colour from its channels. The alpha comes first, as in the name.
public static Color FromArgb(byte alpha, byte red, byte green, byte blue)
Parameters
Returns
FromArgb(int, int, int, int)
Creates a colour from channels from 0 to 255. The alpha comes first, as in the name.
public static Color FromArgb(int alpha, int red, int green, int blue)
Parameters
Returns
FromArgb(float, float, float, float)
Creates a colour from channels from 0 to 1. The alpha comes first, as in the name.
public static Color FromArgb(float alpha, float red, float green, float blue)
Parameters
Returns
FromHex(string)
Parses a hex colour: #RGB, #RGBA, #RRGGBB or #RRGGBBAA. The alpha is opaque when the string has none.
public static Color FromHex(string hexString)
Parameters
hexStringstring
Returns
Exceptions
- ArgumentException
hexStringis not a valid hex colour.
FromRgba(byte, byte, byte, byte)
Creates a colour from its channels. Alpha is opaque when not given.
public static Color FromRgba(byte red, byte green, byte blue, byte alpha = 255)
Parameters
Returns
FromRgba(int, int, int, int)
Creates a colour from channels from 0 to 255. Alpha is opaque when not given.
public static Color FromRgba(int red, int green, int blue, int alpha = 255)
Parameters
Returns
FromRgba(float, float, float, float)
Creates a colour from channels from 0 to 1. Alpha is opaque when not given.
public static Color FromRgba(float red, float green, float blue, float alpha = 1)
Parameters
Returns
GetHashCode()
Returns a hash code based on all four channels, consistent with Equals(object).
public override int GetHashCode()
Returns
IsValid(string)
Whether colorString is accepted by Translate(string).
public static bool IsValid(string colorString)
Parameters
colorStringstring
Returns
ToHexString()
Returns the colour as #RRGGBBAA, the form FromHex(string) and view XML read, so
the string parses back to the same colour.
public string ToHexString()
Returns
ToString()
Converts the color to a string in the format "rgba(r, g, b, a)".
public override string ToString()
Returns
- string
The string representation of the color.
Translate(string)
Parses a colour string. Accepts hex (#RGB, #RGBA, #RRGGBB or #RRGGBBAA), rgb(r, g, b), rgba(r, g, b, a) and argb(a, r, g, b), and HTML colour names. In the rgb forms the channels are 0 to 255; the alpha is 0 to 255 or, as a decimal, 0 to 1.
public static Color Translate(string colorString)
Parameters
colorStringstring
Returns
Exceptions
- ArgumentException
colorStringis not a colour in one of these forms.
Operators
operator +(Color, Color)
Adds each channel of the two colours, clamped to 255. Alpha is added too.
public static Color operator +(Color left, Color right)
Parameters
Returns
operator ==(Color, Color)
Whether the two colours have the same channels.
public static bool operator ==(Color left, Color right)
Parameters
Returns
implicit operator Color(Color)
Converts the color to a System.Drawing.Color.
public static implicit operator Color(Color color)
Parameters
colorColor
Returns
implicit operator Color(SKColor)
Converts a SkiaSharp colour with the same channels.
public static implicit operator Color(SKColor color)
Parameters
colorSKColor
Returns
implicit operator Color(Color)
Converts a Color with the same channels.
public static implicit operator Color(Color color)
Parameters
colorColor
Returns
implicit operator Color(string)
Parses colorString with Translate(string).
public static implicit operator Color(string colorString)
Parameters
colorStringstring
Returns
operator !=(Color, Color)
Whether the two colours differ in any channel.
public static bool operator !=(Color left, Color right)
Parameters
Returns
operator -(Color, Color)
Subtracts each channel of right from left, clamped to 0. Alpha is subtracted too.
public static Color operator -(Color left, Color right)