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
| Name | Description |
|---|---|
| Rgba32(byte, byte, byte, byte) | Initializes a new instance of the Rgba32 struct. |
Rgba32(byte, byte, byte, byte)
Rgba32.csMethods
| Name | Description |
|---|---|
| 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. |
GetHashCode()
Rgba32.csParseCss(ReadOnlySpan<char>)
Rgba32.csParses 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
valueReadOnlySpan<char>- The text.
Returns
Rgba32 The color.
Exceptions
FormatExceptionvalueis 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.csParses a color written in hexadecimal, as in CSS: #RGB, #RGBA, #RRGGBB or #RRGGBBAA.
public static Rgba32 ParseHex(ReadOnlySpan<char> value)Parameters
valueReadOnlySpan<char>- The text.
Returns
Rgba32 The color.
Exceptions
FormatExceptionvalueis 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.csFormats 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.csToString()
Rgba32.csTryParseCss(ReadOnlySpan<char>, Rgba32)
Rgba32.csTries to parse a color written in CSS Color 4, as Rgba32.ParseCss does.
public static bool TryParseCss(ReadOnlySpan<char> value, out Rgba32 result)Parameters
valueReadOnlySpan<char>- The text.
resultRgba32- 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.csTries to parse a color written in hexadecimal, as Rgba32.ParseHex does.
public static bool TryParseHex(ReadOnlySpan<char> value, out Rgba32 result)Parameters
valueReadOnlySpan<char>- The text.
resultRgba32- 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
| Name | Description |
|---|---|
| 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.csimplicit operator Rgba64(Rgba32)
Rgba32.csoperator !=(Rgba32, Rgba32)
Rgba32.csFields
| Name | Description |
|---|---|
| A | The straight alpha component (0 is fully transparent, 255 is fully opaque). |
| B | The blue component. |
| G | The green component. |
| R | The red component. |
A
The straight alpha component (0 is fully transparent, 255 is fully opaque).
public byte AB
The blue component.
public byte BG
The green component.
public byte GR
The red component.
public byte R