Struct Color
Represents a 24-bit color encoded in ARGB32 format.
[JsonConverter(typeof(ColorJsonConverter))]
public readonly record struct Color : ISpanParsable<Color>, IParsable<Color>, IUtf8SpanParsable<Color>, ISpanFormattable, IFormattable, IUtf8SpanFormattable, IMinMaxValue<Color>, IEquatable<Color>
- Implements
- Inherited Members
Constructors
- Color(int)
Initializes a new instance of the Color class with an encoded signed 32-bit color value in ARGB32 format.
- Color(int, int, int, int)
Initializes a new instance of the Colorstruct using the supplied component values.
- Color(string)
Initializes a new instance of the Color color from string. See TryParse(string, out Color?) for details.
- Color(uint)
Initializes a new instance of the Color class with an encoded unsigned 32-bit color value in ARGB32 format.
- Color(in ColorName16)
Initializes a new instance of the Color color from a legacy 16-color named value.
Fields
- A
The value of the alpha channel component
- B
The value of the blue color component.
- Black
The black color.
- Blue
The blue color.
- BrightBlue
The bright bBlue color.
- BrightCyan
The bright cyan color.
- BrightGreen
The bright green color.
- BrightMagenta
The bright magenta color.
- BrightRed
The bright red color.
- BrightYellow
The bright yellow color.
- Cyan
The cyan color.
- DarkGray
The dark gray color.
- G
The value of the green color component.
- Gray
The gray color.
- Green
The green color.
- Magenta
The magenta color.
- R
The value of the red color component.
- Red
The red color.
- White
The White color.
- Yellow
The yellow color.
Properties
- Colors16
Gets or sets the 3-byte/6-character hexadecimal value for each of the legacy 16-color values.
- MaxValue
Gets the maximum value of the current type.
- MinValue
Gets the minimum value of the current type.
Methods
- GetAnsiColorCode()
Gets the Color using a legacy 16-color ColorName16 value. get will return the closest 16 color match to the true color when no exact value is found.
- GetClosestNamedColor16()
Gets the Color using a legacy 16-color ColorName16 value. get will return the closest 16 color match to the true color when no exact value is found.
- GetDarkerColor()
Gets a color that is the same hue as the current color, but with a different lightness.
- GetHashCode()
Returns the hash code for this instance.
- GetHighlightColor()
Gets a color that is the same hue as the current color, but with a different lightness.
- IsClosestToNamedColor16(in ColorName16)
Determines if the closest named Color to this is the provided
namedColor
.
- IsColorClosestToNamedColor16(in Color, in ColorName16)
Determines if the closest named Color to
color
/> is the providednamedColor
.
- Parse(ReadOnlySpan<byte>, IFormatProvider?)
Parses a span of UTF-8 characters into a value.
- Parse(ReadOnlySpan<char>, IFormatProvider?)
Converts the provided ReadOnlySpan<T> of char to a new Color value.
- ToString()
Converts the color to a string representation.
- ToString(string?, IFormatProvider?)
Returns a string that represents the current object.
- TryFormat(Span<byte>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance as UTF-8 into the provided span of bytes.
- TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance into the provided span of characters.
- TryParse(ReadOnlySpan<byte>, IFormatProvider?, out Color)
Tries to parse a span of UTF-8 characters into a value.
- TryParse(ReadOnlySpan<char>, IFormatProvider?, out Color)
Converts the provided ReadOnlySpan<T> of char to a new Color value.
- TryParse(string, out Color?)
Converts the provided string to a new Color instance.
Operators
- explicit operator Vector3(Color)
Implicit conversion from Color to Vector3 via Vector3(float, float, float) where ( X, Y, Z) is (R,G,B).
- implicit operator Color(int)
Implicit conversion from int to Color, via the Color(int) costructor.
- implicit operator Color(Vector4)
Implicit conversion from Vector4 to Color, where (X, Y, Z, W) is (A,R, G,B), via Color(int, int, int, int).
- implicit operator Color(uint)
Implicit conversion from uint to Color, via the Color(uint) costructor.
- implicit operator int(Color)
Implicit conversion from Color to int by returning the value of the Rgba field.
- implicit operator uint(Color)
Implicit conversion from Color to uint by returning the value of the Argb field.
- implicit operator Color(ColorName16)
Implicit conversion from GetClosestNamedColor16(Color) to Color via lookup from ColorName16ToColorMap.