Struct Color
- Namespace
- SixLabors.ImageSharp
- Assembly
- SixLabors.ImageSharp.dll
Represents a color value that is convertible to any IPixel<TSelf> type.
public readonly struct Color : IEquatable<Color>
- Implements
- Inherited Members
Remarks
The internal representation and layout of this structure is hidden by intention. It's not serializable, and it should not be considered as part of a contract. Unlike System.Drawing.Color, Color has to be converted to a specific pixel value to query the color components.
Constructors
Color(Abgr32)
Initializes a new instance of the Color struct.
public Color(Abgr32 pixel)
Parameters
Color(Argb32)
Initializes a new instance of the Color struct.
public Color(Argb32 pixel)
Parameters
Color(Bgr24)
Initializes a new instance of the Color struct.
public Color(Bgr24 pixel)
Parameters
Color(Bgra32)
Initializes a new instance of the Color struct.
public Color(Bgra32 pixel)
Parameters
Color(L16)
Initializes a new instance of the Color struct.
public Color(L16 pixel)
Parameters
Color(La32)
Initializes a new instance of the Color struct.
public Color(La32 pixel)
Parameters
Color(Rgb24)
Initializes a new instance of the Color struct.
public Color(Rgb24 pixel)
Parameters
Color(Rgb48)
Initializes a new instance of the Color struct.
public Color(Rgb48 pixel)
Parameters
Color(Rgba32)
Initializes a new instance of the Color struct.
public Color(Rgba32 pixel)
Parameters
Color(Rgba64)
Initializes a new instance of the Color struct.
public Color(Rgba64 pixel)
Parameters
Color(Vector4)
Initializes a new instance of the Color struct.
public Color(Vector4 vector)
Parameters
Fields
AliceBlue
Represents a
public static readonly Color AliceBlue
Field Value
AntiqueWhite
Represents a
public static readonly Color AntiqueWhite
Field Value
Aqua
Represents a
public static readonly Color Aqua
Field Value
Aquamarine
Represents a
public static readonly Color Aquamarine
Field Value
Azure
Represents a
public static readonly Color Azure
Field Value
Beige
Represents a
public static readonly Color Beige
Field Value
Bisque
Represents a
public static readonly Color Bisque
Field Value
Black
Represents a
public static readonly Color Black
Field Value
BlanchedAlmond
Represents a
public static readonly Color BlanchedAlmond
Field Value
Blue
Represents a
public static readonly Color Blue
Field Value
BlueViolet
Represents a
public static readonly Color BlueViolet
Field Value
Brown
Represents a
public static readonly Color Brown
Field Value
BurlyWood
Represents a
public static readonly Color BurlyWood
Field Value
CadetBlue
Represents a
public static readonly Color CadetBlue
Field Value
Chartreuse
Represents a
public static readonly Color Chartreuse
Field Value
Chocolate
Represents a
public static readonly Color Chocolate
Field Value
Coral
Represents a
public static readonly Color Coral
Field Value
CornflowerBlue
Represents a
public static readonly Color CornflowerBlue
Field Value
Cornsilk
Represents a
public static readonly Color Cornsilk
Field Value
Crimson
Represents a
public static readonly Color Crimson
Field Value
Cyan
Represents a
public static readonly Color Cyan
Field Value
DarkBlue
Represents a
public static readonly Color DarkBlue
Field Value
DarkCyan
Represents a
public static readonly Color DarkCyan
Field Value
DarkGoldenrod
Represents a
public static readonly Color DarkGoldenrod
Field Value
DarkGray
Represents a
public static readonly Color DarkGray
Field Value
DarkGreen
Represents a
public static readonly Color DarkGreen
Field Value
DarkGrey
Represents a
public static readonly Color DarkGrey
Field Value
DarkKhaki
Represents a
public static readonly Color DarkKhaki
Field Value
DarkMagenta
Represents a
public static readonly Color DarkMagenta
Field Value
DarkOliveGreen
Represents a
public static readonly Color DarkOliveGreen
Field Value
DarkOrange
Represents a
public static readonly Color DarkOrange
Field Value
DarkOrchid
Represents a
public static readonly Color DarkOrchid
Field Value
DarkRed
Represents a
public static readonly Color DarkRed
Field Value
DarkSalmon
Represents a
public static readonly Color DarkSalmon
Field Value
DarkSeaGreen
Represents a
public static readonly Color DarkSeaGreen
Field Value
DarkSlateBlue
Represents a
public static readonly Color DarkSlateBlue
Field Value
DarkSlateGray
Represents a
public static readonly Color DarkSlateGray
Field Value
DarkSlateGrey
Represents a
public static readonly Color DarkSlateGrey
Field Value
DarkTurquoise
Represents a
public static readonly Color DarkTurquoise
Field Value
DarkViolet
Represents a
public static readonly Color DarkViolet
Field Value
DeepPink
Represents a
public static readonly Color DeepPink
Field Value
DeepSkyBlue
Represents a
public static readonly Color DeepSkyBlue
Field Value
DimGray
Represents a
public static readonly Color DimGray
Field Value
DimGrey
Represents a
public static readonly Color DimGrey
Field Value
DodgerBlue
Represents a
public static readonly Color DodgerBlue
Field Value
Firebrick
Represents a
public static readonly Color Firebrick
Field Value
FloralWhite
Represents a
public static readonly Color FloralWhite
Field Value
ForestGreen
Represents a
public static readonly Color ForestGreen
Field Value
Fuchsia
Represents a
public static readonly Color Fuchsia
Field Value
Gainsboro
Represents a
public static readonly Color Gainsboro
Field Value
GhostWhite
Represents a
public static readonly Color GhostWhite
Field Value
Gold
Represents a
public static readonly Color Gold
Field Value
Goldenrod
Represents a
public static readonly Color Goldenrod
Field Value
Gray
Represents a
public static readonly Color Gray
Field Value
Green
Represents a
public static readonly Color Green
Field Value
GreenYellow
Represents a
public static readonly Color GreenYellow
Field Value
Grey
Represents a
public static readonly Color Grey
Field Value
Honeydew
Represents a
public static readonly Color Honeydew
Field Value
HotPink
Represents a
public static readonly Color HotPink
Field Value
IndianRed
Represents a
public static readonly Color IndianRed
Field Value
Indigo
Represents a
public static readonly Color Indigo
Field Value
Ivory
Represents a
public static readonly Color Ivory
Field Value
Khaki
Represents a
public static readonly Color Khaki
Field Value
Lavender
Represents a
public static readonly Color Lavender
Field Value
LavenderBlush
Represents a
public static readonly Color LavenderBlush
Field Value
LawnGreen
Represents a
public static readonly Color LawnGreen
Field Value
LemonChiffon
Represents a
public static readonly Color LemonChiffon
Field Value
LightBlue
Represents a
public static readonly Color LightBlue
Field Value
LightCoral
Represents a
public static readonly Color LightCoral
Field Value
LightCyan
Represents a
public static readonly Color LightCyan
Field Value
LightGoldenrodYellow
Represents a
public static readonly Color LightGoldenrodYellow
Field Value
LightGray
Represents a
public static readonly Color LightGray
Field Value
LightGreen
Represents a
public static readonly Color LightGreen
Field Value
LightGrey
Represents a
public static readonly Color LightGrey
Field Value
LightPink
Represents a
public static readonly Color LightPink
Field Value
LightSalmon
Represents a
public static readonly Color LightSalmon
Field Value
LightSeaGreen
Represents a
public static readonly Color LightSeaGreen
Field Value
LightSkyBlue
Represents a
public static readonly Color LightSkyBlue
Field Value
LightSlateGray
Represents a
public static readonly Color LightSlateGray
Field Value
LightSlateGrey
Represents a
public static readonly Color LightSlateGrey
Field Value
LightSteelBlue
Represents a
public static readonly Color LightSteelBlue
Field Value
LightYellow
Represents a
public static readonly Color LightYellow
Field Value
Lime
Represents a
public static readonly Color Lime
Field Value
LimeGreen
Represents a
public static readonly Color LimeGreen
Field Value
Linen
Represents a
public static readonly Color Linen
Field Value
Magenta
Represents a
public static readonly Color Magenta
Field Value
Maroon
Represents a
public static readonly Color Maroon
Field Value
MediumAquamarine
Represents a
public static readonly Color MediumAquamarine
Field Value
MediumBlue
Represents a
public static readonly Color MediumBlue
Field Value
MediumOrchid
Represents a
public static readonly Color MediumOrchid
Field Value
MediumPurple
Represents a
public static readonly Color MediumPurple
Field Value
MediumSeaGreen
Represents a
public static readonly Color MediumSeaGreen
Field Value
MediumSlateBlue
Represents a
public static readonly Color MediumSlateBlue
Field Value
MediumSpringGreen
Represents a
public static readonly Color MediumSpringGreen
Field Value
MediumTurquoise
Represents a
public static readonly Color MediumTurquoise
Field Value
MediumVioletRed
Represents a
public static readonly Color MediumVioletRed
Field Value
MidnightBlue
Represents a
public static readonly Color MidnightBlue
Field Value
MintCream
Represents a
public static readonly Color MintCream
Field Value
MistyRose
Represents a
public static readonly Color MistyRose
Field Value
Moccasin
Represents a
public static readonly Color Moccasin
Field Value
NavajoWhite
Represents a
public static readonly Color NavajoWhite
Field Value
Navy
Represents a
public static readonly Color Navy
Field Value
OldLace
Represents a
public static readonly Color OldLace
Field Value
Olive
Represents a
public static readonly Color Olive
Field Value
OliveDrab
Represents a
public static readonly Color OliveDrab
Field Value
Orange
Represents a
public static readonly Color Orange
Field Value
OrangeRed
Represents a
public static readonly Color OrangeRed
Field Value
Orchid
Represents a
public static readonly Color Orchid
Field Value
PaleGoldenrod
Represents a
public static readonly Color PaleGoldenrod
Field Value
PaleGreen
Represents a
public static readonly Color PaleGreen
Field Value
PaleTurquoise
Represents a
public static readonly Color PaleTurquoise
Field Value
PaleVioletRed
Represents a
public static readonly Color PaleVioletRed
Field Value
PapayaWhip
Represents a
public static readonly Color PapayaWhip
Field Value
PeachPuff
Represents a
public static readonly Color PeachPuff
Field Value
Peru
Represents a
public static readonly Color Peru
Field Value
Pink
Represents a
public static readonly Color Pink
Field Value
Plum
Represents a
public static readonly Color Plum
Field Value
PowderBlue
Represents a
public static readonly Color PowderBlue
Field Value
Purple
Represents a
public static readonly Color Purple
Field Value
RebeccaPurple
Represents a
public static readonly Color RebeccaPurple
Field Value
Red
Represents a
public static readonly Color Red
Field Value
RosyBrown
Represents a
public static readonly Color RosyBrown
Field Value
RoyalBlue
Represents a
public static readonly Color RoyalBlue
Field Value
SaddleBrown
Represents a
public static readonly Color SaddleBrown
Field Value
Salmon
Represents a
public static readonly Color Salmon
Field Value
SandyBrown
Represents a
public static readonly Color SandyBrown
Field Value
SeaGreen
Represents a
public static readonly Color SeaGreen
Field Value
SeaShell
Represents a
public static readonly Color SeaShell
Field Value
Sienna
Represents a
public static readonly Color Sienna
Field Value
Silver
Represents a
public static readonly Color Silver
Field Value
SkyBlue
Represents a
public static readonly Color SkyBlue
Field Value
SlateBlue
Represents a
public static readonly Color SlateBlue
Field Value
SlateGray
Represents a
public static readonly Color SlateGray
Field Value
SlateGrey
Represents a
public static readonly Color SlateGrey
Field Value
Snow
Represents a
public static readonly Color Snow
Field Value
SpringGreen
Represents a
public static readonly Color SpringGreen
Field Value
SteelBlue
Represents a
public static readonly Color SteelBlue
Field Value
Tan
Represents a
public static readonly Color Tan
Field Value
Teal
Represents a
public static readonly Color Teal
Field Value
Thistle
Represents a
public static readonly Color Thistle
Field Value
Tomato
Represents a
public static readonly Color Tomato
Field Value
Transparent
Represents a
public static readonly Color Transparent
Field Value
Turquoise
Represents a
public static readonly Color Turquoise
Field Value
Violet
Represents a
public static readonly Color Violet
Field Value
Wheat
Represents a
public static readonly Color Wheat
Field Value
White
Represents a
public static readonly Color White
Field Value
WhiteSmoke
Represents a
public static readonly Color WhiteSmoke
Field Value
Yellow
Represents a
public static readonly Color Yellow
Field Value
YellowGreen
Represents a
public static readonly Color YellowGreen
Field Value
Properties
WebSafePalette
Gets a collection of named, web safe colors as defined in the CSS Color Module Level 4.
public static ReadOnlyMemory<Color> WebSafePalette { get; }
Property Value
WernerPalette
Gets a collection of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821. The hex codes were collected and defined by Nicholas Rougeux https://www.c82.net/werner.
public static ReadOnlyMemory<Color> WernerPalette { get; }
Property Value
Methods
Equals(Color)
public bool Equals(Color other)
Parameters
other
Color
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
FromPixel<TPixel>(TPixel)
Creates a Color from the given TPixel
.
public static Color FromPixel<TPixel>(TPixel pixel) where TPixel : unmanaged, IPixel<TPixel>
Parameters
pixel
TPixelThe pixel to convert from.
Returns
Type Parameters
TPixel
The pixel format.
FromRgb(byte, byte, byte)
Creates a Color from RGB bytes.
public static Color FromRgb(byte r, byte g, byte b)
Parameters
r
byteThe red component (0-255).
g
byteThe green component (0-255).
b
byteThe blue component (0-255).
Returns
FromRgba(byte, byte, byte, byte)
Creates a Color from RGBA bytes.
public static Color FromRgba(byte r, byte g, byte b, byte a)
Parameters
r
byteThe red component (0-255).
g
byteThe green component (0-255).
b
byteThe blue component (0-255).
a
byteThe alpha component (0-255).
Returns
GetHashCode()
public override int GetHashCode()
Returns
Parse(string)
Creates a new instance of the Color struct from the given input string.
public static Color Parse(string input)
Parameters
input
stringThe name of the color or the hexadecimal representation of the combined color components arranged in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
Returns
Exceptions
- ArgumentException
Input string is not in the correct format.
ParseHex(string)
Creates a new instance of the Color struct from the given hexadecimal string.
public static Color ParseHex(string hex)
Parameters
hex
stringThe hexadecimal representation of the combined color components arranged in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
Returns
ToHex()
Gets the hexadecimal representation of the color instance in rrggbbaa form.
public string ToHex()
Returns
- string
A hexadecimal string representation of the value.
ToPixel<TPixel>()
Converts the color instance to a specified TPixel
type.
public TPixel ToPixel<TPixel>() where TPixel : unmanaged, IPixel<TPixel>
Returns
- TPixel
The pixel value.
Type Parameters
TPixel
The pixel type to convert to.
ToPixel<TPixel>(ReadOnlySpan<Color>, Span<TPixel>)
Bulk converts a span of Color to a span of a specified TPixel
type.
public static void ToPixel<TPixel>(ReadOnlySpan<Color> source, Span<TPixel> destination) where TPixel : unmanaged, IPixel<TPixel>
Parameters
source
ReadOnlySpan<Color>The source color span.
destination
Span<TPixel>The destination pixel span.
Type Parameters
TPixel
The pixel type to convert to.
ToString()
public override string ToString()
Returns
TryParse(string, out Color)
Attempts to creates a new instance of the Color struct from the given input string.
public static bool TryParse(string input, out Color result)
Parameters
input
stringThe name of the color or the hexadecimal representation of the combined color components arranged in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
result
ColorWhen this method returns, contains the Color equivalent of the hexadecimal input.
Returns
TryParseHex(string, out Color)
Attempts to creates a new instance of the Color struct from the given hexadecimal string.
public static bool TryParseHex(string hex, out Color result)
Parameters
hex
stringThe hexadecimal representation of the combined color components arranged in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
result
ColorWhen this method returns, contains the Color equivalent of the hexadecimal input.
Returns
WithAlpha(float)
Alters the alpha channel of the color, returning a new instance.
public Color WithAlpha(float alpha)
Parameters
alpha
floatThe new value of alpha [0..1].
Returns
- Color
The color having it's alpha channel altered.
Operators
operator ==(Color, Color)
Checks whether two Color structures are equal.
public static bool operator ==(Color left, Color right)
Parameters
Returns
- bool
True if the
left
parameter is equal to theright
parameter; otherwise, false.
explicit operator Vector4(Color)
public static explicit operator Vector4(Color color)
Parameters
Returns
explicit operator Color(Vector4)
public static explicit operator Color(Vector4 source)
Parameters
Returns
operator !=(Color, Color)
Checks whether two Color structures are not equal.
public static bool operator !=(Color left, Color right)
Parameters
Returns
- bool
True if the
left
parameter is not equal to theright
parameter; otherwise, false.