Rgba32 Struct

A pixel with 8-bit red, green, blue and straight (non-premultiplied) alpha components, stored in RGBA byte order.

public struct Rgba32 : IEquatable<Rgba32>
Implements

Constructors

NameDescription
Rgba32(byte, byte, byte, byte)Initializes a new instance of the Rgba32 struct.

Rgba32(byte, byte, byte, byte)

Rgba32.cs

Initializes a new instance of the Rgba32 struct.

public Rgba32(byte r, byte g, byte b, byte a = 255)

Parameters

r byte
The red component.
g byte
The green component.
b byte
The blue component.
a byte
The straight alpha component. Defaults to fully opaque.

Methods

NameDescription
Equals(Rgba32)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Indicates whether this instance and a specified object are equal.
GetHashCode()Returns the hash code for this instance.
ParseCss(ReadOnlySpan<char>)Parses a color written in CSS Color 4: hexadecimal (#RRGGBB, ...), or one of the functions rgb(), rgba(), hsl(), hsla(), hwb(), lab(), lch(), oklab() and oklch(), converted to sRGB.
ParseHex(ReadOnlySpan<char>)Parses a color written in hexadecimal, as in CSS: #RGB, #RGBA, #RRGGBB or #RRGGBBAA.
ToHexString()Formats the color in hexadecimal, as in CSS: #RRGGBB when it is opaque, #RRGGBBAA otherwise.
ToRgba64()Converts this pixel to Rgba64 using exact full-range expansion (v * 257).
ToString()Returns the fully qualified type name of this instance.
TryParseCss(ReadOnlySpan<char>, Rgba32)Tries to parse a color written in CSS Color 4, as Rgba32.ParseCss does.
TryParseHex(ReadOnlySpan<char>, Rgba32)Tries to parse a color written in hexadecimal, as Rgba32.ParseHex does.

Equals overloads

Equals(Rgba32)

Rgba32.cs

Indicates whether the current object is equal to another object of the same type.

public readonly bool Equals(Rgba32 other)
Parameters
other Rgba32
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Rgba32.cs

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current instance.
Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Rgba32.cs

Returns the hash code for this instance.

public override readonly int GetHashCode()

Returns

int A 32-bit signed integer that is the hash code for this instance.

ParseCss(ReadOnlySpan<char>)

Rgba32.cs

Parses a color written in CSS Color 4: hexadecimal (#RRGGBB, ...), or one of the functions rgb(), rgba(), hsl(), hsla(), hwb(), lab(), lch(), oklab() and oklch(), converted to sRGB.

public static Rgba32 ParseCss(ReadOnlySpan<char> value)

Parameters

value ReadOnlySpan<char>
The text.

Returns

Rgba32 The color.

Exceptions

FormatException
value is not a supported CSS color.

Remarks

The hexadecimal form needs its # here. The functions accept the modern syntax (components separated by white space, an optional / alpha, none) and, for rgb() and hsl(), the legacy syntax with commas; see CieLab.Parse and the other color value types for the components. A color outside sRGB is clipped component by component (not gamut-mapped as a browser does), and each component is rounded to the nearest 8-bit value. Named colors, calc(), relative colors and the color() function are not supported.

ParseHex(ReadOnlySpan<char>)

Rgba32.cs

Parses a color written in hexadecimal, as in CSS: #RGB, #RGBA, #RRGGBB or #RRGGBBAA.

public static Rgba32 ParseHex(ReadOnlySpan<char> value)

Parameters

value ReadOnlySpan<char>
The text.

Returns

Rgba32 The color.

Exceptions

FormatException
value is not a hexadecimal color.

Remarks

The # is optional and the digits are not case-sensitive. A short form doubles each digit (#F80 is #FF8800); a form without alpha is opaque. Nothing else is accepted: no white space, no color name.

ToHexString()

Rgba32.cs

Formats the color in hexadecimal, as in CSS: #RRGGBB when it is opaque, #RRGGBBAA otherwise.

public readonly string ToHexString()

Returns

string The text, with uppercase digits; Rgba32.ParseHex reads it back.

ToRgba64()

Rgba32.cs

Converts this pixel to Rgba64 using exact full-range expansion (v * 257).

public readonly Rgba64 ToRgba64()

Returns

Rgba64 The widened pixel.

ToString()

Rgba32.cs

Returns the fully qualified type name of this instance.

public override readonly string ToString()

Returns

string The fully qualified type name.

TryParseCss(ReadOnlySpan<char>, Rgba32)

Rgba32.cs

Tries to parse a color written in CSS Color 4, as Rgba32.ParseCss does.

public static bool TryParseCss(ReadOnlySpan<char> value, out Rgba32 result)

Parameters

value ReadOnlySpan<char>
The text.
result Rgba32
The color, or the default value when the text is not a supported CSS color.

Returns

bool true if the text is a supported CSS color.

TryParseHex(ReadOnlySpan<char>, Rgba32)

Rgba32.cs

Tries to parse a color written in hexadecimal, as Rgba32.ParseHex does.

public static bool TryParseHex(ReadOnlySpan<char> value, out Rgba32 result)

Parameters

value ReadOnlySpan<char>
The text.
result Rgba32
The color, or the default value when the text is not a hexadecimal color.

Returns

bool true if the text is a hexadecimal color.

Operators

NameDescription
operator ==(Rgba32, Rgba32)Compares two pixels for equality.
implicit operator Rgba64(Rgba32)Converts a pixel to Rgba64 using exact full-range expansion. The conversion is lossless.
operator !=(Rgba32, Rgba32)Compares two pixels for inequality.

operator ==(Rgba32, Rgba32)

Rgba32.cs

Compares two pixels for equality.

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

Parameters

left Rgba32
The first pixel.
right Rgba32
The second pixel.

Returns

bool true if all components are equal; otherwise false.

implicit operator Rgba64(Rgba32)

Rgba32.cs

Converts a pixel to Rgba64 using exact full-range expansion. The conversion is lossless.

public static implicit operator Rgba64(Rgba32 value)

Parameters

value Rgba32
The pixel to convert.

Returns

Rgba64

operator !=(Rgba32, Rgba32)

Rgba32.cs

Compares two pixels for inequality.

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

Parameters

left Rgba32
The first pixel.
right Rgba32
The second pixel.

Returns

bool true if any component differs; otherwise false.

Fields

NameDescription
AThe straight alpha component (0 is fully transparent, 255 is fully opaque).
BThe blue component.
GThe green component.
RThe red component.

A

The straight alpha component (0 is fully transparent, 255 is fully opaque).

public byte A

B

The blue component.

public byte B

G

The green component.

public byte G

R

The red component.

public byte R