Struct Color<T>
Represents a color with red, green, blue and alpha components
public readonly struct Color<T> : IEquatable<Color<T>>, ISpanFormattable, IFormattable, IEqualityOperators<Color<T>, Color<T>, bool> where T : unmanaged, IEquatable<T>, IFormattable, ISpanFormattable, IEqualityOperators<T, T, bool>
Type Parameters
TThe type of the color components
- Implements
-
IEquatable<Color<T>>
- Inherited Members
Remarks
Most often the type T is either byte for 32-bit pixel values with unsigned integer ranges from 0 to 255 for each component,
or float for 128-bit pixel values with floating-point ranges from 0 to 1 for each component.
Color<byte> values can be directly reinterpreted as an integer-packed color which uses the Rgba32 format (Abgr8888 on little-endian systems and Rgba8888 on big-endian systems).
Color<float> values can be directly reinterpreted as a float-packed color which uses the Rgba128Float format.
Constructors
Color(in T, in T, in T, in T)
Represents a color with red, green, blue and alpha components
[SetsRequiredMembers]
public Color(in T r, in T g, in T b, in T a)
Parameters
rTThe value of the red component
gTThe value of the green component
bTThe value of the blue component
aTThe value of the alpha component
Remarks
Most often the type T is either byte for 32-bit pixel values with unsigned integer ranges from 0 to 255 for each component,
or float for 128-bit pixel values with floating-point ranges from 0 to 1 for each component.
Color<byte> values can be directly reinterpreted as an integer-packed color which uses the Rgba32 format (Abgr8888 on little-endian systems and Rgba8888 on big-endian systems).
Color<float> values can be directly reinterpreted as a float-packed color which uses the Rgba128Float format.
Properties
A
Gets or initializes the alpha component value of the color
public required T A { get; init; }
Property Value
- T
The alpha component value of the color
B
Gets or initializes the blue component value of the color
public required T B { get; init; }
Property Value
- T
The blue component value of the color
G
Gets or initializes the green component value of the color
public required T G { get; init; }
Property Value
- T
The green component value of the color
R
Gets or initializes the red component value of the color
public required T R { get; init; }
Property Value
- T
The red component value of the color
Methods
Deconstruct(out T, out T, out T, out T)
Deconstructs the color into its red, green, blue and alpha component values
public void Deconstruct(out T r, out T g, out T b, out T a)
Parameters
rTThe red component value of the color
gTThe green component value of the color
bTThe blue component value of the color
aTThe alpha component value of the color
Equals(in Color<T>)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(in Color<T> other)
Parameters
otherColor<T>An object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
ToString(IFormatProvider?)
Formats the value of the current instance using the specified format.
public string ToString(IFormatProvider? formatProvider)
Parameters
formatProviderIFormatProviderThe provider to use to format the value.
-or-
A null reference (
Nothingin Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.
Returns
- string
The value of the current instance in the specified format.
ToString(string?)
Formats the value of the current instance using the specified format.
public string ToString(string? format)
Parameters
formatstringThe format to use.
-or-
A null reference (
Nothingin Visual Basic) to use the default format defined for the type of the IFormattable implementation.
Returns
- string
The value of the current instance in the specified format.
ToString(string?, IFormatProvider?)
Formats the value of the current instance using the specified format.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format to use.
-or-
A null reference (
Nothingin Visual Basic) to use the default format defined for the type of the IFormattable implementation.formatProviderIFormatProviderThe provider to use to format the value.
-or-
A null reference (
Nothingin Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.
Returns
- string
The value of the current instance in the specified format.
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance into the provided span of characters.
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)
Parameters
destinationSpan<char>The span in which to write this instance's value formatted as a span of characters.
charsWrittenintWhen this method returns, contains the number of characters that were written in
destination.formatReadOnlySpan<char>A span containing the characters that represent a standard or custom format string that defines the acceptable format for
destination.providerIFormatProviderAn optional object that supplies culture-specific formatting information for
destination.
Returns
Operators
operator ==(in Color<T>, in Color<T>)
Compares two values to determine equality.
public static bool operator ==(in Color<T> left, in Color<T> right)
Parameters
Returns
implicit operator (T R, T G, T B, T A)(in Color<T>)
Converts a color to a tuple of its red, green, blue and alpha component values
public static implicit operator (T R, T G, T B, T A)(in Color<T> color)
Parameters
colorColor<T>The color to convert
Returns
- (T R, T G, T B, T A)
A tuple containing the red, green, blue and alpha component values of the color
implicit operator Color<T>(in (T R, T G, T B, T A))
Converts a tuple of red, green, blue and alpha component values to a color
public static implicit operator Color<T>(in (T R, T G, T B, T A) rgba)
Parameters
Returns
- Color<T>
A color with the specified red, green, blue and alpha component values
operator !=(in Color<T>, in Color<T>)
Compares two values to determine inequality.
public static bool operator !=(in Color<T> left, in Color<T> right)