Table of Contents

Struct Color

Namespace
BSGameLib.Game.Drawing
Assembly
BSGameLib.Game.dll

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
a byte

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 Color
a float

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

r byte
g byte
b byte
a byte

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

r int
g int
b int
a int

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

r float
g float
b float
a float

Properties

A

The alpha channel, from 0 (transparent) to 255 (opaque).

public byte A { get; }

Property Value

byte

AliceBlue

The named colour #F0F8FF.

public static Color AliceBlue { get; }

Property Value

Color

AntiqueWhite

The named colour #FAEBD7.

public static Color AntiqueWhite { get; }

Property Value

Color

Aqua

The named colour #00FFFF.

public static Color Aqua { get; }

Property Value

Color

Aquamarine

The named colour #7FFFD4.

public static Color Aquamarine { get; }

Property Value

Color

Azure

The named colour #F0FFFF.

public static Color Azure { get; }

Property Value

Color

B

The blue channel, from 0 to 255.

public byte B { get; }

Property Value

byte

Beige

The named colour #F5F5DC.

public static Color Beige { get; }

Property Value

Color

Bisque

The named colour #FFE4C4.

public static Color Bisque { get; }

Property Value

Color

Black

The named colour #000000.

public static Color Black { get; }

Property Value

Color

BlanchedAlmond

The named colour #FFEBCD.

public static Color BlanchedAlmond { get; }

Property Value

Color

Blue

The named colour #0000FF.

public static Color Blue { get; }

Property Value

Color

BlueViolet

The named colour #8A2BE2.

public static Color BlueViolet { get; }

Property Value

Color

Brown

The named colour #A52A2A.

public static Color Brown { get; }

Property Value

Color

BurlyWood

The named colour #DEB887.

public static Color BurlyWood { get; }

Property Value

Color

CadetBlue

The named colour #5F9EA0.

public static Color CadetBlue { get; }

Property Value

Color

Chartreuse

The named colour #7FFF00.

public static Color Chartreuse { get; }

Property Value

Color

Chocolate

The named colour #D2691E.

public static Color Chocolate { get; }

Property Value

Color

Coral

The named colour #FF7F50.

public static Color Coral { get; }

Property Value

Color

CornflowerBlue

The named colour #6495ED.

public static Color CornflowerBlue { get; }

Property Value

Color

Cornsilk

The named colour #FFF8DC.

public static Color Cornsilk { get; }

Property Value

Color

Crimson

The named colour #DC143C.

public static Color Crimson { get; }

Property Value

Color

Cyan

The named colour #00FFFF.

public static Color Cyan { get; }

Property Value

Color

DarkBlue

The named colour #00008B.

public static Color DarkBlue { get; }

Property Value

Color

DarkCyan

The named colour #008B8B.

public static Color DarkCyan { get; }

Property Value

Color

DarkGoldenrod

The named colour #B8860B.

public static Color DarkGoldenrod { get; }

Property Value

Color

DarkGray

The named colour #A9A9A9.

public static Color DarkGray { get; }

Property Value

Color

DarkGreen

The named colour #006400.

public static Color DarkGreen { get; }

Property Value

Color

DarkKhaki

The named colour #BDB76B.

public static Color DarkKhaki { get; }

Property Value

Color

DarkMagenta

The named colour #8B008B.

public static Color DarkMagenta { get; }

Property Value

Color

DarkOliveGreen

The named colour #556B2F.

public static Color DarkOliveGreen { get; }

Property Value

Color

DarkOrange

The named colour #FF8C00.

public static Color DarkOrange { get; }

Property Value

Color

DarkOrchid

The named colour #9932CC.

public static Color DarkOrchid { get; }

Property Value

Color

DarkRed

The named colour #8B0000.

public static Color DarkRed { get; }

Property Value

Color

DarkSalmon

The named colour #E9967A.

public static Color DarkSalmon { get; }

Property Value

Color

DarkSeaGreen

The named colour #8FBC8F.

public static Color DarkSeaGreen { get; }

Property Value

Color

DarkSlateBlue

The named colour #483D8B.

public static Color DarkSlateBlue { get; }

Property Value

Color

DarkSlateGray

The named colour #2F4F4F.

public static Color DarkSlateGray { get; }

Property Value

Color

DarkTurquoise

The named colour #00CED1.

public static Color DarkTurquoise { get; }

Property Value

Color

DarkViolet

The named colour #9400D3.

public static Color DarkViolet { get; }

Property Value

Color

DeepPink

The named colour #FF1493.

public static Color DeepPink { get; }

Property Value

Color

DeepSkyBlue

The named colour #00BFFF.

public static Color DeepSkyBlue { get; }

Property Value

Color

DimGray

The named colour #696969.

public static Color DimGray { get; }

Property Value

Color

DodgerBlue

The named colour #1E90FF.

public static Color DodgerBlue { get; }

Property Value

Color

Firebrick

The named colour #B22222.

public static Color Firebrick { get; }

Property Value

Color

FloralWhite

The named colour #FFFAF0.

public static Color FloralWhite { get; }

Property Value

Color

ForestGreen

The named colour #228B22.

public static Color ForestGreen { get; }

Property Value

Color

Fuchsia

The named colour #FF00FF.

public static Color Fuchsia { get; }

Property Value

Color

G

The green channel, from 0 to 255.

public byte G { get; }

Property Value

byte

Gainsboro

The named colour #DCDCDC.

public static Color Gainsboro { get; }

Property Value

Color

GhostWhite

The named colour #F8F8FF.

public static Color GhostWhite { get; }

Property Value

Color

Gold

The named colour #FFD700.

public static Color Gold { get; }

Property Value

Color

Goldenrod

The named colour #DAA520.

public static Color Goldenrod { get; }

Property Value

Color

Gray

The named colour #808080.

public static Color Gray { get; }

Property Value

Color

Green

The named colour #008000.

public static Color Green { get; }

Property Value

Color

GreenYellow

The named colour #ADFF2F.

public static Color GreenYellow { get; }

Property Value

Color

Honeydew

The named colour #F0FFF0.

public static Color Honeydew { get; }

Property Value

Color

HotPink

The named colour #FF69B4.

public static Color HotPink { get; }

Property Value

Color

IndianRed

The named colour #CD5C5C.

public static Color IndianRed { get; }

Property Value

Color

Indigo

The named colour #4B0082.

public static Color Indigo { get; }

Property Value

Color

Ivory

The named colour #FFFFF0.

public static Color Ivory { get; }

Property Value

Color

Khaki

The named colour #F0E68C.

public static Color Khaki { get; }

Property Value

Color

Lavender

The named colour #E6E6FA.

public static Color Lavender { get; }

Property Value

Color

LavenderBlush

The named colour #FFF0F5.

public static Color LavenderBlush { get; }

Property Value

Color

LawnGreen

The named colour #7CFC00.

public static Color LawnGreen { get; }

Property Value

Color

LemonChiffon

The named colour #FFFACD.

public static Color LemonChiffon { get; }

Property Value

Color

LightBlue

The named colour #ADD8E6.

public static Color LightBlue { get; }

Property Value

Color

LightCoral

The named colour #F08080.

public static Color LightCoral { get; }

Property Value

Color

LightCyan

The named colour #E0FFFF.

public static Color LightCyan { get; }

Property Value

Color

LightGoldenrodYellow

The named colour #FAFAD2.

public static Color LightGoldenrodYellow { get; }

Property Value

Color

LightGray

The named colour #D3D3D3.

public static Color LightGray { get; }

Property Value

Color

LightGreen

The named colour #90EE90.

public static Color LightGreen { get; }

Property Value

Color

LightPink

The named colour #FFB6C1.

public static Color LightPink { get; }

Property Value

Color

LightSalmon

The named colour #FFA07A.

public static Color LightSalmon { get; }

Property Value

Color

LightSeaGreen

The named colour #20B2AA.

public static Color LightSeaGreen { get; }

Property Value

Color

LightSkyBlue

The named colour #87CEFA.

public static Color LightSkyBlue { get; }

Property Value

Color

LightSlateGray

The named colour #778899.

public static Color LightSlateGray { get; }

Property Value

Color

LightSteelBlue

The named colour #B0C4DE.

public static Color LightSteelBlue { get; }

Property Value

Color

LightYellow

The named colour #FFFFE0.

public static Color LightYellow { get; }

Property Value

Color

Lime

The named colour #00FF00.

public static Color Lime { get; }

Property Value

Color

LimeGreen

The named colour #32CD32.

public static Color LimeGreen { get; }

Property Value

Color

Linen

The named colour #FAF0E6.

public static Color Linen { get; }

Property Value

Color

Magenta

The named colour #FF00FF.

public static Color Magenta { get; }

Property Value

Color

Maroon

The named colour #800000.

public static Color Maroon { get; }

Property Value

Color

MediumAquamarine

The named colour #66CDAA.

public static Color MediumAquamarine { get; }

Property Value

Color

MediumBlue

The named colour #0000CD.

public static Color MediumBlue { get; }

Property Value

Color

MediumOrchid

The named colour #BA55D3.

public static Color MediumOrchid { get; }

Property Value

Color

MediumPurple

The named colour #9370DB.

public static Color MediumPurple { get; }

Property Value

Color

MediumSeaGreen

The named colour #3CB371.

public static Color MediumSeaGreen { get; }

Property Value

Color

MediumSlateBlue

The named colour #7B68EE.

public static Color MediumSlateBlue { get; }

Property Value

Color

MediumSpringGreen

The named colour #00FA9A.

public static Color MediumSpringGreen { get; }

Property Value

Color

MediumTurquoise

The named colour #48D1CC.

public static Color MediumTurquoise { get; }

Property Value

Color

MediumVioletRed

The named colour #C71585.

public static Color MediumVioletRed { get; }

Property Value

Color

MidnightBlue

The named colour #191970.

public static Color MidnightBlue { get; }

Property Value

Color

MintCream

The named colour #F5FFFA.

public static Color MintCream { get; }

Property Value

Color

MistyRose

The named colour #FFE4E1.

public static Color MistyRose { get; }

Property Value

Color

Moccasin

The named colour #FFE4B5.

public static Color Moccasin { get; }

Property Value

Color

NavajoWhite

The named colour #FFDEAD.

public static Color NavajoWhite { get; }

Property Value

Color

Navy

The named colour #000080.

public static Color Navy { get; }

Property Value

Color

OldLace

The named colour #FDF5E6.

public static Color OldLace { get; }

Property Value

Color

Olive

The named colour #808000.

public static Color Olive { get; }

Property Value

Color

OliveDrab

The named colour #6B8E23.

public static Color OliveDrab { get; }

Property Value

Color

Orange

The named colour #FFA500.

public static Color Orange { get; }

Property Value

Color

OrangeRed

The named colour #FF4500.

public static Color OrangeRed { get; }

Property Value

Color

Orchid

The named colour #DA70D6.

public static Color Orchid { get; }

Property Value

Color

PaleGoldenrod

The named colour #EEE8AA.

public static Color PaleGoldenrod { get; }

Property Value

Color

PaleGreen

The named colour #98FB98.

public static Color PaleGreen { get; }

Property Value

Color

PaleTurquoise

The named colour #AFEEEE.

public static Color PaleTurquoise { get; }

Property Value

Color

PaleVioletRed

The named colour #DB7093.

public static Color PaleVioletRed { get; }

Property Value

Color

PapayaWhip

The named colour #FFEFD5.

public static Color PapayaWhip { get; }

Property Value

Color

PeachPuff

The named colour #FFDAB9.

public static Color PeachPuff { get; }

Property Value

Color

Peru

The named colour #CD853F.

public static Color Peru { get; }

Property Value

Color

Pink

The named colour #FFC0CB.

public static Color Pink { get; }

Property Value

Color

Plum

The named colour #DDA0DD.

public static Color Plum { get; }

Property Value

Color

PowderBlue

The named colour #B0E0E6.

public static Color PowderBlue { get; }

Property Value

Color

Purple

The named colour #800080.

public static Color Purple { get; }

Property Value

Color

R

The red channel, from 0 to 255.

public byte R { get; }

Property Value

byte

Red

The named colour #FF0000.

public static Color Red { get; }

Property Value

Color

RosyBrown

The named colour #BC8F8F.

public static Color RosyBrown { get; }

Property Value

Color

RoyalBlue

The named colour #4169E1.

public static Color RoyalBlue { get; }

Property Value

Color

SaddleBrown

The named colour #8B4513.

public static Color SaddleBrown { get; }

Property Value

Color

Salmon

The named colour #FA8072.

public static Color Salmon { get; }

Property Value

Color

SandyBrown

The named colour #F4A460.

public static Color SandyBrown { get; }

Property Value

Color

SeaGreen

The named colour #2E8B57.

public static Color SeaGreen { get; }

Property Value

Color

SeaShell

The named colour #FFF5EE.

public static Color SeaShell { get; }

Property Value

Color

Sienna

The named colour #A0522D.

public static Color Sienna { get; }

Property Value

Color

Silver

The named colour #C0C0C0.

public static Color Silver { get; }

Property Value

Color

SkyBlue

The named colour #87CEEB.

public static Color SkyBlue { get; }

Property Value

Color

SlateBlue

The named colour #6A5ACD.

public static Color SlateBlue { get; }

Property Value

Color

SlateGray

The named colour #708090.

public static Color SlateGray { get; }

Property Value

Color

Snow

The named colour #FFFAFA.

public static Color Snow { get; }

Property Value

Color

SpringGreen

The named colour #00FF7F.

public static Color SpringGreen { get; }

Property Value

Color

SteelBlue

The named colour #4682B4.

public static Color SteelBlue { get; }

Property Value

Color

Tan

The named colour #D2B48C.

public static Color Tan { get; }

Property Value

Color

Teal

The named colour #008080.

public static Color Teal { get; }

Property Value

Color

Thistle

The named colour #D8BFD8.

public static Color Thistle { get; }

Property Value

Color

Tomato

The named colour #FF6347.

public static Color Tomato { get; }

Property Value

Color

Transparent

Fully transparent black, with no colour of its own.

public static Color Transparent { get; }

Property Value

Color

Turquoise

The named colour #40E0D0.

public static Color Turquoise { get; }

Property Value

Color

Violet

The named colour #EE82EE.

public static Color Violet { get; }

Property Value

Color

Wheat

The named colour #F5DEB3.

public static Color Wheat { get; }

Property Value

Color

White

The named colour #FFFFFF.

public static Color White { get; }

Property Value

Color

WhiteSmoke

The named colour #F5F5F5.

public static Color WhiteSmoke { get; }

Property Value

Color

Yellow

The named colour #FFFF00.

public static Color Yellow { get; }

Property Value

Color

YellowGreen

The named colour #9ACD32.

public static Color YellowGreen { get; }

Property Value

Color

Methods

Equals(Color)

Whether all four channels equal those of other.

public bool Equals(Color other)

Parameters

other Color

Returns

bool

Equals(object)

Whether obj is a Color with the same channels.

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

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

alpha byte
red byte
green byte
blue byte

Returns

Color

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

alpha int
red int
green int
blue int

Returns

Color

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

alpha float
red float
green float
blue float

Returns

Color

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

hexString string

Returns

Color

Exceptions

ArgumentException

hexString is 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

red byte
green byte
blue byte
alpha byte

Returns

Color

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

red int
green int
blue int
alpha int

Returns

Color

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

red float
green float
blue float
alpha float

Returns

Color

GetHashCode()

Returns a hash code based on all four channels, consistent with Equals(object).

public override int GetHashCode()

Returns

int

IsValid(string)

Whether colorString is accepted by Translate(string).

public static bool IsValid(string colorString)

Parameters

colorString string

Returns

bool

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

string

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

colorString string

Returns

Color

Exceptions

ArgumentException

colorString is 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

left Color
right Color

Returns

Color

operator ==(Color, Color)

Whether the two colours have the same channels.

public static bool operator ==(Color left, Color right)

Parameters

left Color
right Color

Returns

bool

implicit operator Color(Color)

Converts the color to a System.Drawing.Color.

public static implicit operator Color(Color color)

Parameters

color Color

Returns

Color

implicit operator Color(SKColor)

Converts a SkiaSharp colour with the same channels.

public static implicit operator Color(SKColor color)

Parameters

color SKColor

Returns

Color

implicit operator Color(Color)

Converts a Color with the same channels.

public static implicit operator Color(Color color)

Parameters

color Color

Returns

Color

implicit operator Color(string)

Parses colorString with Translate(string).

public static implicit operator Color(string colorString)

Parameters

colorString string

Returns

Color

operator !=(Color, Color)

Whether the two colours differ in any channel.

public static bool operator !=(Color left, Color right)

Parameters

left Color
right Color

Returns

bool

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)

Parameters

left Color
right Color

Returns

Color