Class Color
Representation of the RGBA color.
Inheritance
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public sealed class Color : ValueType
Constructors
Color(Byte, Byte, Byte, Byte)
Constructs a new Color with given r,g,b,a components (values in range [0;255]).
Declaration
public Color(byte r, byte g, byte b, byte a = 255)
Parameters
|
System.Byte
r
Red component. |
|
System.Byte
g
Green component. |
|
System.Byte
b
Blue component. |
|
System.Byte
a
Alpha component. |
Color(Int32, Int32, Int32, Int32)
Constructs a new Color with given r,g,b,a components (values in range [0;255]).
Declaration
public Color(int r, int g, int b, int a = 255)
Parameters
|
System.Int32
r
Red component. |
|
System.Int32
g
Green component. |
|
System.Int32
b
Blue component. |
|
System.Int32
a
Alpha component. |
Color(Single)
Constructs a new Color with given r,g,b,a component.
Declaration
public Color(float rgba)
Parameters
|
System.Single
rgba
RGBA component. |
Color(Single, Single, Single)
Constructs a new Color with given r,g,b components and sets alpha to 1.
Declaration
public Color(float r, float g, float b)
Parameters
|
System.Single
r
Red component. |
|
System.Single
g
Green component. |
|
System.Single
b
Blue component. |
Color(Single, Single, Single, Single)
Constructs a new Color with given r,g,b,a components (values in range [0;1]).
Declaration
public Color(float r, float g, float b, float a)
Parameters
|
System.Single
r
Red component. |
|
System.Single
g
Green component. |
|
System.Single
b
Blue component. |
|
System.Single
a
Alpha component. |
Color(Single[])
Initializes a new instance of the Color struct.
Declaration
public Color(float[] values)
Parameters
|
System.Single[]
values
The values to assign to the red, green, blue, and alpha components of the color. This must be an array with four elements. |
Exceptions
|
System.ArgumentNullException
Thrown when |
|
System.ArgumentOutOfRangeException
Thrown when |
Fields
A
The alpha channel value.
Declaration
public float A
Field Value
|
System.Single
|
AliceBlue
AntiqueWhite
Aqua
Aquamarine
Azure
B
The blue channel value.
Declaration
public float B
Field Value
|
System.Single
|
Beige
Bisque
Black
BlanchedAlmond
Blue
BlueViolet
Brown
BurlyWood
CadetBlue
Chartreuse
Chocolate
Coral
CornflowerBlue
Cornsilk
Crimson
Cyan
DarkBlue
DarkCyan
DarkGoldenrod
DarkGray
DarkGreen
DarkKhaki
DarkMagenta
DarkOliveGreen
DarkOrange
DarkOrchid
DarkRed
DarkSalmon
DarkSeaGreen
DarkSlateBlue
DarkSlateGray
DarkTurquoise
DarkViolet
DeepPink
DeepSkyBlue
DimGray
DodgerBlue
Firebrick
FloralWhite
ForestGreen
Fuchsia
G
The green channel value.
Declaration
public float G
Field Value
|
System.Single
|
Gainsboro
GhostWhite
Gold
Goldenrod
Gray
Green
GreenYellow
Honeydew
HotPink
IndianRed
Indigo
Ivory
Khaki
Lavender
LavenderBlush
LawnGreen
LemonChiffon
LightBlue
LightCoral
LightCyan
LightGoldenrodYellow
LightGoldenrodYellow color.
Declaration
public static readonly Color LightGoldenrodYellow
Field Value
|
Color
|
LightGray
LightGreen
LightPink
LightSalmon
LightSeaGreen
LightSkyBlue
LightSlateGray
LightSteelBlue
LightYellow
Lime
LimeGreen
Linen
Magenta
Maroon
MediumAquamarine
MediumBlue
MediumOrchid
MediumPurple
MediumSeaGreen
MediumSlateBlue
MediumSpringGreen
MediumSpringGreen color.
Declaration
public static readonly Color MediumSpringGreen
Field Value
|
Color
|
MediumTurquoise
MediumVioletRed
MidnightBlue
MintCream
MistyRose
Moccasin
NavajoWhite
Navy
OldLace
Olive
OliveDrab
Orange
OrangeRed
Orchid
PaleGoldenrod
PaleGreen
PaleTurquoise
PaleVioletRed
PapayaWhip
PeachPuff
Peru
Pink
Plum
PowderBlue
Purple
R
The red channel value.
Declaration
public float R
Field Value
|
System.Single
|
Red
RosyBrown
RoyalBlue
SaddleBrown
Salmon
SandyBrown
SeaGreen
SeaShell
Sienna
Silver
SizeInBytes
The size of the Color type, in bytes.
Declaration
public static readonly int SizeInBytes
Field Value
|
System.Int32
|
SkyBlue
SlateBlue
SlateGray
Snow
SpringGreen
SteelBlue
Tan
Teal
Thistle
Tomato
Transparent
Turquoise
Violet
Wheat
White
WhiteSmoke
Yellow
YellowGreen
Zero
Properties
Default
Item[Int32]
Gets or sets the component at the specified index.
Declaration
public float this[int index] { get; set; }
Parameters
|
System.Int32
index
The index of the component to access. Use 0 for the alpha component, 1 for the red component, 2 for the green component, and 3 for the blue component. |
Property Value
|
System.Single
The value of the red, green, blue, and alpha components, depending on the index. |
Exceptions
|
System.IndexOutOfRangeException
Thrown when the |
MaxColorComponent
Returns the maximum color component value: Max(r,g,b).
Declaration
public float MaxColorComponent { get; }
Property Value
|
System.Single
|
MaxValue
Gets a maximum component value (min of r,g,b,a).
Declaration
public float MaxValue { get; }
Property Value
|
System.Single
|
MinColorComponent
Returns the minimum color component value: Min(r,g,b).
Declaration
public float MinColorComponent { get; }
Property Value
|
System.Single
|
MinValue
Gets a minimum component value (max of r,g,b,a).
Declaration
public float MinValue { get; }
Property Value
|
System.Single
|
ValuesSum
Gets a sum of the component values.
Declaration
public float ValuesSum { get; }
Property Value
|
System.Single
|
Methods
AdjustContrast(Color, Single)
Adjusts the contrast of a color.
Declaration
public static Color AdjustContrast(Color value, float contrast)
Parameters
|
Color
value
The color whose contrast is to be adjusted. |
|
System.Single
contrast
The amount by which to adjust the contrast. |
Returns
|
Color
The adjusted color. |
AdjustContrast(ref Color, Single, out Color)
1 Adjusts the contrast of a color.
Declaration
public static void AdjustContrast(ref Color value, float contrast, out Color result)
Parameters
|
Color
value
The color whose contrast is to be adjusted. |
|
System.Single
contrast
The amount by which to adjust the contrast. |
|
Color
result
When the method completes, contains the adjusted color. |
AdjustSaturation(Color, Single)
Adjusts the saturation of a color.
Declaration
public static Color AdjustSaturation(Color value, float saturation)
Parameters
|
Color
value
The color whose saturation is to be adjusted. |
|
System.Single
saturation
The amount by which to adjust the saturation. |
Returns
|
Color
The adjusted color. |
AdjustSaturation(ref Color, Single, out Color)
Adjusts the saturation of a color.
Declaration
public static void AdjustSaturation(ref Color value, float saturation, out Color result)
Parameters
|
Color
value
The color whose saturation is to be adjusted. |
|
System.Single
saturation
The amount by which to adjust the saturation. |
|
Color
result
When the method completes, contains the adjusted color. |
AlphaMultiplied(Single)
Returns the color with alpha channel multiplied by the given color. The RGB channels remain the same.
Declaration
public Color AlphaMultiplied(float multiplier)
Parameters
|
System.Single
multiplier
The multiplier. |
Returns
|
Color
The modified color. |
Clamp(Color, Color, Color)
Restricts a value to be within a specified range.
Declaration
public static Color Clamp(Color value, Color min, Color max)
Parameters
|
Color
value
The value to clamp. |
|
Color
min
The minimum value. |
|
Color
max
The maximum value. |
Returns
|
Color
The clamped value. |
Clamp(ref Color, ref Color, ref Color, out Color)
Restricts a value to be within a specified range.
Declaration
public static void Clamp(ref Color value, ref Color min, ref Color max, out Color result)
Parameters
|
Color
value
The value to clamp. |
|
Color
min
The minimum value. |
|
Color
max
The maximum value. |
|
Color
result
When the method completes, contains the clamped value. |
Equals(ref Color)
Determines whether the specified Color is equal to this instance.
Declaration
public bool Equals(ref Color other)
Parameters
|
Color
other
The Color to compare with this instance. |
Returns
|
System.Boolean
|
Equals(Object)
Declaration
public override bool Equals(object value)
Parameters
|
System.Object
value
|
Returns
|
System.Boolean
|
FromARGB(UInt32)
Creates Color from the ARGB value (bottom bits contain Blue).
Declaration
public static Color FromARGB(uint argb)
Parameters
|
System.UInt32
argb
The packed ARGB value (bottom bits contain Blue). |
Returns
|
Color
The color. |
FromBgra(Int32)
Converts the color from a packed BGRA integer.
Declaration
public static Color FromBgra(int color)
Parameters
|
System.Int32
color
A packed integer containing all four color components in BGRA order |
Returns
|
Color
A color. |
FromBgra(UInt32)
Converts the color from a packed BGRA integer.
Declaration
public static Color FromBgra(uint color)
Parameters
|
System.UInt32
color
A packed integer containing all four color components in BGRA order |
Returns
|
Color
A color. |
FromHex(String)
Creates Color from the Hex string.
Declaration
public static Color FromHex(string hex)
Parameters
|
System.String
hex
The hexadecimal color string. |
Returns
|
Color
The output color value. |
FromHex(String, out Color)
Creates Color from the Hex string.
Declaration
public static bool FromHex(string hex, out Color color)
Parameters
|
System.String
hex
The hexadecimal color string. |
|
Color
color
The output color value. Valid if method returns true. |
Returns
|
System.Boolean
True if method was able to convert color, otherwise false. |
FromHSV(Float3, Single)
Creates RGB color from Hue[0-360], Saturation[0-1] and Value[0-1] packed to XYZ vector.
Declaration
public static Color FromHSV(Float3 hsv, float alpha = 1F)
Parameters
|
Float3
hsv
The HSV color. |
|
System.Single
alpha
The alpha value. Default is 1. |
Returns
|
Color
The RGB color. |
FromHSV(Single, Single, Single, Single)
Creates RGB color from Hue[0-360], Saturation[0-1] and Value[0-1].
Declaration
public static Color FromHSV(float hue, float saturation, float value, float alpha = 1F)
Parameters
|
System.Single
hue
The hue angle in degrees [0-360]. |
|
System.Single
saturation
The saturation normalized [0-1]. |
|
System.Single
value
The value normalized [0-1]. |
|
System.Single
alpha
The alpha value. Default is 1. |
Returns
|
Color
The RGB color. |
FromRGB(UInt32, Single)
Creates Color from the RGB value (bottom bits contain Blue) and separate alpha channel.
Declaration
public static Color FromRGB(uint rgb, float a = 1F)
Parameters
|
System.UInt32
rgb
The packed RGB value (bottom bits contain Blue). |
|
System.Single
a
The alpha channel value. |
Returns
|
Color
The color. |
FromRGBA(UInt32)
Creates Color from the RGBA value (bottom bits contain Alpha).
Declaration
public static Color FromRGBA(uint rgba)
Parameters
|
System.UInt32
rgba
The packed RGBA value (bottom bits Alpha Red). |
Returns
|
Color
The color. |
GetHashCode()
Declaration
public override int GetHashCode()
Returns
|
System.Int32
|
Lerp(Color, Color, Single)
Linearly interpolates between colors a and b by t.
Declaration
public static Color Lerp(Color a, Color b, float t)
Parameters
|
Color
a
Color a |
|
Color
b
Color b |
|
System.Single
t
Float for combining a and b |
Returns
|
Color
|
Lerp(ref Color, ref Color, Single, out Color)
Linearly interpolates between colors a and b by t.
Declaration
public static void Lerp(ref Color a, ref Color b, float t, out Color result)
Parameters
|
Color
a
Color a |
|
Color
b
Color b |
|
System.Single
t
Float for combining a and b |
|
Color
result
The result. |
Max(Color, Color)
Returns a color containing the largest components of the specified colors.
Declaration
public static Color Max(Color left, Color right)
Parameters
|
Color
left
The first source color. |
|
Color
right
The second source color. |
Returns
|
Color
A color containing the largest components of the source colors. |
Max(ref Color, ref Color, out Color)
Returns a color containing the largest components of the specified colors.
Declaration
public static void Max(ref Color left, ref Color right, out Color result)
Parameters
|
Color
left
The first source color. |
|
Color
right
The second source color. |
|
Color
result
When the method completes, contains an new color composed of the largest components of the source colors. |
Min(Color, Color)
Returns a color containing the smallest components of the specified colors.
Declaration
public static Color Min(Color left, Color right)
Parameters
|
Color
left
The first source color. |
|
Color
right
The second source color. |
Returns
|
Color
A color containing the smallest components of the source colors. |
Min(ref Color, ref Color, out Color)
Returns a color containing the smallest components of the specified colors.
Declaration
public static void Min(ref Color left, ref Color right, out Color result)
Parameters
|
Color
left
The first source color. |
|
Color
right
The second source color. |
|
Color
result
When the method completes, contains an new color composed of the smallest components of the source colors. |
Parse(String)
Creates Color from the text string (hex or color name).
Declaration
public static Color Parse(string text)
Parameters
|
System.String
text
The color string (hex or color name). |
Returns
|
Color
The color. |
ParseHex(String)
Creates Color from the hexadecimal string.
Declaration
public static Color ParseHex(string hexString)
Parameters
|
System.String
hexString
The hexadecimal string. |
Returns
|
Color
The color. |
PremultiplyAlpha(Color)
Premultiplies the color components by the alpha value.
Declaration
public static Color PremultiplyAlpha(Color value)
Parameters
|
Color
value
The color to premultiply. |
Returns
|
Color
A color with premultiplied alpha. |
RGBMultiplied(Color)
Returns the color with RGB channels multiplied by the given color. The alpha channel remains the same.
Declaration
public Color RGBMultiplied(Color multiplier)
Parameters
|
Color
multiplier
The multiplier. |
Returns
|
Color
The modified color. |
RGBMultiplied(Single)
Returns the color with RGB channels multiplied by the given scale factor. The alpha channel remains the same.
Declaration
public Color RGBMultiplied(float multiplier)
Parameters
|
System.Single
multiplier
The multiplier. |
Returns
|
Color
The modified color. |
RGBToHSV(Color, out Single, out Single, out Single)
Convert color from the RGB color space to HSV color space.
Declaration
public static void RGBToHSV(Color rgbColor, out float h, out float s, out float v)
Parameters
|
Color
rgbColor
Color of the RGB. |
|
System.Single
h
The output Hue. |
|
System.Single
s
The output Saturation. |
|
System.Single
v
The output Value. |
ToArray()
Creates an array containing the elements of the color.
Declaration
public float[] ToArray()
Returns
|
System.Single[]
A four-element array containing the components of the color. |
ToBgra()
Converts the color into a packed integer.
Declaration
public int ToBgra()
Returns
|
System.Int32
A packed integer containing all four color components. |
ToBgra(out Byte, out Byte, out Byte, out Byte)
Converts the color into a packed integer.
Declaration
public void ToBgra(out byte r, out byte g, out byte b, out byte a)
Parameters
|
System.Byte
r
|
|
System.Byte
g
|
|
System.Byte
b
|
|
System.Byte
a
|
ToHexString()
Gets the color value as the hexadecimal string (in RGBA order).
Declaration
public string ToHexString()
Returns
|
System.String
Hex string. |
ToHSV()
Gets Hue[0-360], Saturation[0-1] and Value[0-1] from RGB color.
Declaration
public Float3 ToHSV()
Returns
|
Float3
The HSV color. |
ToLinear()
Converts this color from sRGB space to linear space.
Declaration
public Color ToLinear()
Returns
|
Color
A Color in linear space. |
ToRgba()
Converts the color into a packed integer.
Declaration
public int ToRgba()
Returns
|
System.Int32
A packed integer containing all four color components. |
ToSRgb()
Converts this color from linear space to sRGB space.
Declaration
public Color ToSRgb()
Returns
|
Color
A color3 in sRGB space. |
ToString()
Returns a nicely formatted string of this color.
Declaration
public override string ToString()
Returns
|
System.String
|
ToString(String)
Returns a nicely formatted string of this color.
Declaration
public string ToString(string format)
Parameters
|
System.String
format
|
Returns
|
System.String
|
TryParse(String, out Color)
Creates Color from the string (hex or color name).
Declaration
public static bool TryParse(string text, out Color value)
Parameters
|
System.String
text
The color string (hex or color name). |
|
Color
value
Output value. |
Returns
|
System.Boolean
True if value has been parsed, otherwise false. |
TryParseHex(String, out Color)
Creates Color from the hexadecimal string.
Declaration
public static bool TryParseHex(string hexString, out Color value)
Parameters
|
System.String
hexString
The hexadecimal string. |
|
Color
value
Output value. |
Returns
|
System.Boolean
True if value has been parsed, otherwise false. |
Operators
Addition(Color, Color)
Adds two colors.
Declaration
public static Color operator +(Color a, Color b)
Parameters
|
Color
a
The first color. |
|
Color
b
The second color. |
Returns
|
Color
The result of the operator. |
Division(Color, Single)
Divides color by the scale factor.
Declaration
public static Color operator /(Color a, float b)
Parameters
|
Color
a
The first color. |
|
System.Single
b
The division factor. |
Returns
|
Color
The result of the operator. |
Equality(Color, Color)
Compares two colors.
Declaration
public static bool operator ==(Color left, Color right)
Parameters
|
Color
left
The left. |
|
Color
right
The right. |
Returns
|
System.Boolean
True if colors are equal, otherwise false. |
Implicit(Color to Float3)
Declaration
public static implicit operator Float3(Color c)
Parameters
|
Color
c
The color. |
Returns
|
Float3
The result of the conversion. |
Implicit(Color to Float4)
Declaration
public static implicit operator Float4(Color c)
Parameters
|
Color
c
The color. |
Returns
|
Float4
The result of the conversion. |
Implicit(Color to Vector3)
Declaration
public static implicit operator Vector3(Color c)
Parameters
|
Color
c
The color. |
Returns
|
Vector3
The result of the conversion. |
Implicit(Color to Vector4)
Declaration
public static implicit operator Vector4(Color c)
Parameters
|
Color
c
The color. |
Returns
|
Vector4
The result of the conversion. |
Implicit(Float3 to Color)
Declaration
public static implicit operator Color(Float3 v)
Parameters
|
Float3
v
The vector. |
Returns
|
Color
The result of the conversion. |
Implicit(Float4 to Color)
Declaration
public static implicit operator Color(Float4 v)
Parameters
|
Float4
v
The vector. |
Returns
|
Color
The result of the conversion. |
Implicit(Vector3 to Color)
Declaration
public static implicit operator Color(Vector3 v)
Parameters
|
Vector3
v
The vector. |
Returns
|
Color
The result of the conversion. |
Implicit(Vector4 to Color)
Declaration
public static implicit operator Color(Vector4 v)
Parameters
|
Vector4
v
The vector. |
Returns
|
Color
The result of the conversion. |
Inequality(Color, Color)
Compares two colors.
Declaration
public static bool operator !=(Color left, Color right)
Parameters
|
Color
left
The left. |
|
Color
right
The right. |
Returns
|
System.Boolean
True if colors are not equal, otherwise false. |
Multiply(Color, Color)
Multiplies color components by the other color components.
Declaration
public static Color operator *(Color a, Color b)
Parameters
|
Color
a
The first color. |
|
Color
b
The second color. |
Returns
|
Color
The result of the operator. |
Multiply(Color, Single)
Multiplies color components by the scale factor.
Declaration
public static Color operator *(Color a, float b)
Parameters
|
Color
a
The color. |
|
System.Single
b
The scale. |
Returns
|
Color
The result of the operator. |
Multiply(Single, Color)
Multiplies color components by the scale factor.
Declaration
public static Color operator *(float b, Color a)
Parameters
|
System.Single
b
The scale. |
|
Color
a
The color. |
Returns
|
Color
The result of the operator. |
Subtraction(Color, Color)
Subtracts one color from the another.
Declaration
public static Color operator -(Color a, Color b)
Parameters
|
Color
a
The first color. |
|
Color
b
The second color. |
Returns
|
Color
The result of the operator. |