Struct Color
- Namespace
- Stride.Core.Mathematics
- Assembly
- Stride.Core.Mathematics.dll
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
- Implements
Constructors
Color(Vector3)
Initializes a new instance of the Color struct. Alpha is set to 255.
Parameters
value
Vector3The red, green, and blue components of the color.
Color(Vector3, float)
Initializes a new instance of the Color struct.
Parameters
value
Vector3The red, green, and blue components of the color.
alpha
floatThe alpha component of the color.
Color(Vector4)
Initializes a new instance of the Color struct.
Parameters
value
Vector4The red, green, blue, and alpha components of the color.
Color(byte)
Initializes a new instance of the Color struct.
Parameters
value
byteThe value that will be assigned to all components.
Color(byte, byte, byte)
Initializes a new instance of the Color struct. Alpha is set to 255.
Parameters
red
byteThe red component of the color.
green
byteThe green component of the color.
blue
byteThe blue component of the color.
Color(byte, byte, byte, byte)
Initializes a new instance of the Color struct.
Parameters
red
byteThe red component of the color.
green
byteThe green component of the color.
blue
byteThe blue component of the color.
alpha
byteThe alpha component of the color.
Color(byte[])
Initializes a new instance of the Color struct.
Parameters
values
byte[]The values to assign to the red, green, blue, or alpha components of the color. This must be an array with four elements.
Exceptions
- Argument
Null Exception Thrown when
values
isnull
.- Argument
Out OfRange Exception Thrown when
values
contains more or less than four elements.
Color(int)
Initializes a new instance of the Color struct.
Parameters
rgba
intA packed integer containing all four color components in RGBA order.
Color(float)
Initializes a new instance of the Color struct.
Parameters
value
floatThe value that will be assigned to all components.
Color(float, float, float)
Initializes a new instance of the Color struct. Alpha is set to 255.
Parameters
red
floatThe red component of the color.
green
floatThe green component of the color.
blue
floatThe blue component of the color.
Color(float, float, float, float)
Initializes a new instance of the Color struct.
Parameters
red
floatThe red component of the color.
green
floatThe green component of the color.
blue
floatThe blue component of the color.
alpha
floatThe alpha component of the color.
Color(float[])
Initializes a new instance of the Color struct.
Parameters
values
float[]The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four elements.
Exceptions
- Argument
Null Exception Thrown when
values
isnull
.- Argument
Out OfRange Exception Thrown when
values
contains more or less than four elements.
Color(uint)
Initializes a new instance of the Color struct.
Parameters
rgba
uintA packed integer containing all four color components in RGBA order.
Fields
A
The alpha component of the color.
Field Value
AliceBlue
AliceBlue color.
Field Value
AntiqueWhite
AntiqueWhite color.
Field Value
Aqua
Aqua color.
Field Value
Aquamarine
Aquamarine color.
Field Value
Azure
Azure color.
Field Value
B
The blue component of the color.
Field Value
Beige
Beige color.
Field Value
Bisque
Bisque color.
Field Value
Black
Black color.
Field Value
BlanchedAlmond
BlanchedAlmond color.
Field Value
Blue
Blue color.
Field Value
BlueViolet
BlueViolet color.
Field Value
Brown
Brown color.
Field Value
BurlyWood
BurlyWood color.
Field Value
CadetBlue
CadetBlue color.
Field Value
Chartreuse
Chartreuse color.
Field Value
Chocolate
Chocolate color.
Field Value
Coral
Coral color.
Field Value
CornflowerBlue
CornflowerBlue color.
Field Value
Cornsilk
Cornsilk color.
Field Value
Crimson
Crimson color.
Field Value
Cyan
Cyan color.
Field Value
DarkBlue
DarkBlue color.
Field Value
DarkCyan
DarkCyan color.
Field Value
DarkGoldenrod
DarkGoldenrod color.
Field Value
DarkGray
DarkGray color.
Field Value
DarkGreen
DarkGreen color.
Field Value
DarkKhaki
DarkKhaki color.
Field Value
DarkMagenta
DarkMagenta color.
Field Value
DarkOliveGreen
DarkOliveGreen color.
Field Value
DarkOrange
DarkOrange color.
Field Value
DarkOrchid
DarkOrchid color.
Field Value
DarkRed
DarkRed color.
Field Value
DarkSalmon
DarkSalmon color.
Field Value
DarkSeaGreen
DarkSeaGreen color.
Field Value
DarkSlateBlue
DarkSlateBlue color.
Field Value
DarkSlateGray
DarkSlateGray color.
Field Value
DarkTurquoise
DarkTurquoise color.
Field Value
DarkViolet
DarkViolet color.
Field Value
DeepPink
DeepPink color.
Field Value
DeepSkyBlue
DeepSkyBlue color.
Field Value
DimGray
DimGray color.
Field Value
DodgerBlue
DodgerBlue color.
Field Value
Firebrick
Firebrick color.
Field Value
FloralWhite
FloralWhite color.
Field Value
ForestGreen
ForestGreen color.
Field Value
Fuchsia
Fuchsia color.
Field Value
G
The green component of the color.
Field Value
Gainsboro
Gainsboro color.
Field Value
GhostWhite
GhostWhite color.
Field Value
Gold
Gold color.
Field Value
Goldenrod
Goldenrod color.
Field Value
Gray
Gray color.
Field Value
Green
Green color.
Field Value
GreenYellow
GreenYellow color.
Field Value
Honeydew
Honeydew color.
Field Value
HotPink
HotPink color.
Field Value
IndianRed
IndianRed color.
Field Value
Indigo
Indigo color.
Field Value
Ivory
Ivory color.
Field Value
Khaki
Khaki color.
Field Value
Lavender
Lavender color.
Field Value
LavenderBlush
LavenderBlush color.
Field Value
LawnGreen
LawnGreen color.
Field Value
LemonChiffon
LemonChiffon color.
Field Value
LightBlue
LightBlue color.
Field Value
LightCoral
LightCoral color.
Field Value
LightCyan
LightCyan color.
Field Value
LightGoldenrodYellow
LightGoldenrodYellow color.
Field Value
LightGray
LightGray color.
Field Value
LightGreen
LightGreen color.
Field Value
LightPink
LightPink color.
Field Value
LightSalmon
LightSalmon color.
Field Value
LightSeaGreen
LightSeaGreen color.
Field Value
LightSkyBlue
LightSkyBlue color.
Field Value
LightSlateGray
LightSlateGray color.
Field Value
LightSteelBlue
LightSteelBlue color.
Field Value
LightYellow
LightYellow color.
Field Value
Lime
Lime color.
Field Value
LimeGreen
LimeGreen color.
Field Value
Linen
Linen color.
Field Value
Magenta
Magenta color.
Field Value
Maroon
Maroon color.
Field Value
MediumAquamarine
MediumAquamarine color.
Field Value
MediumBlue
MediumBlue color.
Field Value
MediumOrchid
MediumOrchid color.
Field Value
MediumPurple
MediumPurple color.
Field Value
MediumSeaGreen
MediumSeaGreen color.
Field Value
MediumSlateBlue
MediumSlateBlue color.
Field Value
MediumSpringGreen
MediumSpringGreen color.
Field Value
MediumTurquoise
MediumTurquoise color.
Field Value
MediumVioletRed
MediumVioletRed color.
Field Value
MidnightBlue
MidnightBlue color.
Field Value
MintCream
MintCream color.
Field Value
MistyRose
MistyRose color.
Field Value
Moccasin
Moccasin color.
Field Value
NavajoWhite
NavajoWhite color.
Field Value
Navy
Navy color.
Field Value
OldLace
OldLace color.
Field Value
Olive
Olive color.
Field Value
OliveDrab
OliveDrab color.
Field Value
Orange
Orange color.
Field Value
OrangeRed
OrangeRed color.
Field Value
Orchid
Orchid color.
Field Value
PaleGoldenrod
PaleGoldenrod color.
Field Value
PaleGreen
PaleGreen color.
Field Value
PaleTurquoise
PaleTurquoise color.
Field Value
PaleVioletRed
PaleVioletRed color.
Field Value
PapayaWhip
PapayaWhip color.
Field Value
PeachPuff
PeachPuff color.
Field Value
Peru
Peru color.
Field Value
Pink
Pink color.
Field Value
Plum
Plum color.
Field Value
PowderBlue
PowderBlue color.
Field Value
Purple
Purple color.
Field Value
R
The red component of the color.
Field Value
Red
Red color.
Field Value
RosyBrown
RosyBrown color.
Field Value
RoyalBlue
RoyalBlue color.
Field Value
SaddleBrown
SaddleBrown color.
Field Value
Salmon
Salmon color.
Field Value
SandyBrown
SandyBrown color.
Field Value
SeaGreen
SeaGreen color.
Field Value
SeaShell
SeaShell color.
Field Value
Sienna
Sienna color.
Field Value
Silver
Silver color.
Field Value
SkyBlue
SkyBlue color.
Field Value
SlateBlue
SlateBlue color.
Field Value
SlateGray
SlateGray color.
Field Value
Snow
Snow color.
Field Value
SpringGreen
SpringGreen color.
Field Value
SteelBlue
SteelBlue color.
Field Value
Tan
Tan color.
Field Value
Teal
Teal color.
Field Value
Thistle
Thistle color.
Field Value
Tomato
Tomato color.
Field Value
Transparent
Transparent color.
Field Value
Turquoise
Turquoise color.
Field Value
VeryDimGray
VeryDimGray color.
Field Value
Violet
Violet color.
Field Value
Wheat
Wheat color.
Field Value
White
White color.
Field Value
WhiteSmoke
WhiteSmoke color.
Field Value
Yellow
Yellow color.
Field Value
YellowGreen
YellowGreen color.
Field Value
Zero
Zero color.
Field Value
Properties
this[int]
Gets or sets the component at the specified index.
Parameters
index
intThe index of the component to access. Use 0 for the red(R) component, 1 for the green(G) component, 2 for the blue(B) component, and 3 for the alpha(A) component.
Property Value
- byte
The value of the red, green, blue, or alpha component, depending on the index.
Exceptions
- Argument
Out OfRange Exception Thrown when the
index
is out of the range [0, 3].
Methods
Add(Color, Color)
Adds two colors.
Parameters
Returns
- Color
The sum of the two colors.
Add(ref Color, ref Color, out Color)
Adds two colors.
Parameters
left
ColorThe first color to add.
right
ColorThe second color to add.
result
ColorWhen the method completes, completes the sum of the two colors.
AdjustContrast(Color, float)
Adjusts the contrast of a color.
Parameters
value
ColorThe color whose contrast is to be adjusted.
contrast
floatThe amount by which to adjust the contrast.
Returns
- Color
The adjusted color.
AdjustContrast(ref Color, float, out Color)
Adjusts the contrast of a color.
Parameters
value
ColorThe color whose contrast is to be adjusted.
contrast
floatThe amount by which to adjust the contrast.
result
ColorWhen the method completes, contains the adjusted color.
AdjustSaturation(Color, float)
Adjusts the saturation of a color.
Parameters
value
ColorThe color whose saturation is to be adjusted.
saturation
floatThe amount by which to adjust the saturation.
Returns
- Color
The adjusted color.
AdjustSaturation(ref Color, float, out Color)
Adjusts the saturation of a color.
Parameters
value
ColorThe color whose saturation is to be adjusted.
saturation
floatThe amount by which to adjust the saturation.
result
ColorWhen the method completes, contains the adjusted color.
Clamp(Color, Color, Color)
Restricts a value to be within a specified range.
Parameters
Returns
- Color
The clamped value.
Clamp(ref Color, ref Color, ref Color, out Color)
Restricts a value to be within a specified range.
Parameters
value
ColorThe value to clamp.
min
ColorThe minimum value.
max
ColorThe maximum value.
result
ColorWhen the method completes, contains the clamped value.
Equals(Color)
Determines whether the specified Color is equal to this instance.
Parameters
Returns
Equals(object)
Determines whether the specified object is equal to this instance.
Parameters
Returns
FromAbgr(int)
Converts the color from a packed ABGR integer.
Parameters
color
intA packed integer containing all four color components in ABGR order
Returns
- Color
A color.
FromAbgr(uint)
Converts the color from a packed ABGR integer.
Parameters
color
uintA packed integer containing all four color components in ABGR order
Returns
- Color
A color.
FromBgra(int)
Converts the color from a packed BGRA integer.
Parameters
color
intA packed integer containing all four color components in BGRA order
Returns
- Color
A color.
FromBgra(uint)
Converts the color from a packed BGRA integer.
Parameters
color
uintA packed integer containing all four color components in BGRA order
Returns
- Color
A color.
FromRgba(int)
Converts the color from a packed RGBA integer.
Parameters
color
intA packed integer containing all four color components in RGBA order
Returns
- Color
A color.
FromRgba(uint)
Converts the color from a packed RGBA integer.
Parameters
color
uintA packed integer containing all four color components in RGBA order
Returns
- Color
A color.
GetBrightness()
Gets the brightness.
Returns
GetHashCode()
Returns a hash code for this instance.
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
GetHue()
Gets the hue.
Returns
GetSaturation()
Gets the saturation.
Returns
Lerp(Color, Color, float)
Performs a linear interpolation between two colors.
Parameters
start
ColorStart color.
end
ColorEnd color.
amount
floatValue between 0 and 1 indicating the weight of
end
.
Returns
- Color
The linear interpolation of the two colors.
Remarks
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Lerp(ref Color, ref Color, float, out Color)
Performs a linear interpolation between two colors.
Parameters
start
ColorStart color.
end
ColorEnd color.
amount
floatValue between 0 and 1 indicating the weight of
end
.result
ColorWhen the method completes, contains the linear interpolation of the two colors.
Remarks
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Max(Color, Color)
Returns a color containing the largest components of the specified colorss.
Parameters
Returns
- Color
A color containing the largest components of the source colors.
Max(ref Color, ref Color, out Color)
Returns a color containing the smallest components of the specified colors.
Parameters
left
ColorThe first source color.
right
ColorThe second source color.
result
ColorWhen 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.
Parameters
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.
Parameters
left
ColorThe first source color.
right
ColorThe second source color.
result
ColorWhen the method completes, contains an new color composed of the smallest components of the source colors.
Modulate(Color, Color)
Modulates two colors.
Parameters
Returns
- Color
The modulated color.
Modulate(ref Color, ref Color, out Color)
Modulates two colors.
Parameters
left
ColorThe first color to modulate.
right
ColorThe second color to modulate.
result
ColorWhen the method completes, contains the modulated color.
Negate(Color)
Negates a color.
Parameters
value
ColorThe color to negate.
Returns
- Color
The negated color.
Negate(ref Color, out Color)
Negates a color.
Parameters
value
ColorThe color to negate.
result
ColorWhen the method completes, contains the negated color.
Scale(Color, float)
Scales a color.
Parameters
Returns
- Color
The scaled color.
Scale(ref Color, float, out Color)
Scales a color.
Parameters
value
ColorThe color to scale.
scale
floatThe amount by which to scale.
result
ColorWhen the method completes, contains the scaled color.
SmoothStep(Color, Color, float)
Performs a cubic interpolation between two colors.
Parameters
start
ColorStart color.
end
ColorEnd color.
amount
floatValue between 0 and 1 indicating the weight of
end
.
Returns
- Color
The cubic interpolation of the two colors.
SmoothStep(ref Color, ref Color, float, out Color)
Performs a cubic interpolation between two colors.
Parameters
start
ColorStart color.
end
ColorEnd color.
amount
floatValue between 0 and 1 indicating the weight of
end
.result
ColorWhen the method completes, contains the cubic interpolation of the two colors.
Subtract(Color, Color)
Subtracts two colors.
Parameters
Returns
- Color
The difference of the two colors.
Subtract(ref Color, ref Color, out Color)
Subtracts two colors.
Parameters
left
ColorThe first color to subtract.
right
ColorThe second color to subtract.
result
ColorWHen the method completes, contains the difference of the two colors.
ToAbgr()
Converts the color into a packed integer.
Returns
- int
A packed integer containing all four color components.
ToArgb()
Converts the color into a packed integer.
Returns
- int
A packed integer containing all four color components.
ToArray()
Creates an array containing the elements of the color.
Returns
- byte[]
A four-element array containing the components of the color in RGBA order.
ToBgra()
Converts the color into a packed integer.
Returns
- int
A packed integer containing all four color components.
ToColor3()
Converts the color into a three component color.
Returns
- Color3
A three component color containing the red, green, and blue components of the color.
ToColor4()
Convert this instance to a Color4
Returns
- Color4
The result of the conversion.
ToRgba()
Converts the color into a packed integer.
Returns
- int
A packed integer containing all four color components.
ToString()
Returns a string that represents this instance.
Returns
ToVector3()
Converts the color into a three component vector.
Returns
- Vector3
A three component vector containing the red, green, and blue components of the color.
ToVector4()
Converts the color into a four component vector.
Returns
- Vector4
A four component vector containing all four color components.
Operators
operator +(Color, Color)
Adds two colors.
Parameters
Returns
- Color
The sum of the two colors.
operator ==(Color, Color)
Tests for equality between two objects.
Parameters
Returns
- bool
true
ifleft
has the same value asright
; otherwise,false
.
explicit operator Color3(Color)
Parameters
value
ColorThe value.
Returns
- Color3
The result of the conversion.
explicit operator Vector3(Color)
Parameters
value
ColorThe value.
Returns
- Vector3
The result of the conversion.
explicit operator Vector4(Color)
Parameters
value
ColorThe value.
Returns
- Vector4
The result of the conversion.
explicit operator int(Color)
Parameters
value
ColorThe value.
Returns
- int
The result of the conversion.
explicit operator Color(Color3)
Parameters
value
Color3The value.
Returns
- Color
The result of the conversion.
explicit operator Color(Color4)
Parameters
value
Color4The value.
Returns
- Color
The result of the conversion.
explicit operator Color(Vector3)
Parameters
value
Vector3The value.
Returns
- Color
The result of the conversion.
explicit operator Color(Vector4)
Parameters
value
Vector4The value.
Returns
- Color
The result of the conversion.
explicit operator Color(int)
Parameters
value
intThe value.
Returns
- Color
The result of the conversion.
implicit operator Color4(Color)
Parameters
value
ColorThe value.
Returns
- Color4
The result of the conversion.
operator !=(Color, Color)
Tests for inequality between two objects.
Parameters
Returns
- bool
true
ifleft
has a different value thanright
; otherwise,false
.
operator *(Color, Color)
Modulates two colors.
Parameters
Returns
- Color
The modulated color.
operator *(Color, float)
Scales a color.
Parameters
Returns
- Color
The scaled color.
operator *(float, Color)
Scales a color.
Parameters
Returns
- Color
The scaled color.
operator -(Color, Color)
Subtracts two colors.
Parameters
Returns
- Color
The difference of the two colors.
operator -(Color)
Negates a color.
Parameters
value
ColorThe color to negate.
Returns
- Color
A negated color.
operator +(Color)
Assert a color (return it unchanged).
Parameters
value
ColorThe color to assert (unchanged).
Returns
- Color
The asserted (unchanged) color.