Struct Color32
public readonly struct Color32 : IEquatable<Color32>
- Implements
- Inherited Members
Examples
// Opaque white
var white = new Color32(255, 255, 255);
// Semi-transparent red
var red50 = new Color32(255, 0, 0, 128);
// Pack/unpack AARRGGBB
int argb = red50.ToArgb(); // 0x80FF0000
var again = Color32.FromArgb(argb); // equal to red50
Remarks
Each component is stored as a byte in the range 0..255
.
Packed integer format: 0xAARRGGBB
(alpha in the most significant byte).
Constructors
- Color32(byte, byte, byte)
Initializes a new opaque Color32 from red, green, and blue components (alpha=255).
- Color32(byte, byte, byte, byte)
Initializes a new Color32 from red, green, blue, and alpha components.
Fields
- A
Alpha channel (0..255). 0=fully transparent, 255=fully opaque.
- B
Blue channel intensity (0..255).
- G
Green channel intensity (0..255).
- R
Red channel intensity (0..255).
Methods
- Deconstruct(out byte, out byte, out byte, out byte)
Deconstructs the color into (r, g, b, a).
- FromArgb(int)
Creates a Color32 from a packed 32-bit ARGB integer (
0xAARRGGBB
).
- FromBgr(int)
Creates an opaque Color32 from a packed 24-bit BGR integer (
0xBBGGRR
).
- FromBgr(int, byte)
Creates a Color32 from a packed 24-bit BGR integer (
0xBBGGRR
) and an alpha.
- FromRgb(int)
Creates an opaque Color32 from a packed 24-bit RGB integer (
0xRRGGBB
).
- FromRgb(int, byte)
Creates a Color32 from a packed 24-bit RGB integer (
0xRRGGBB
) and an alpha.
- GetLuminance()
Computes the perceived brightness (luminance) of this color as a single 8-bit grayscale value. Uses Rec. 601 luma weights: 0.299 * R + 0.587 * G + 0.114 * B. The result is in the range 0 (black) to 255 (white).
- ToArgb()
Converts this color to a packed 32-bit ARGB integer (
0xAARRGGBB
).
- ToRgb()
Converts this color to a packed 24-bit RGB integer (
0xRRGGBB
), dropping alpha.
- WithAlpha(byte)
Returns a copy of this color with a different alpha.