Color

A straight (non-premultiplied) RGBA color with each channel in the range 0..1.
public readonly record struct Color(double Red, double Green, double Blue, double Alpha)

Constructors

Creates an opaque color (alpha 1).

public Color(
  double red,
  double green,
  double blue)
ParameterSummary
double redThe red channel.
double greenThe green channel.
double blueThe blue channel.

Initializes a new instance of the Color struct.

public Color(
  double Red,
  double Green,
  double Blue,
  double Alpha)
ParameterSummary
double RedThe red channel.
double GreenThe green channel.
double BlueThe blue channel.
double AlphaThe alpha channel.

Properties

Alpha

The alpha channel.

Type: double

public double Alpha { get; init; }

Blue

The blue channel.

Type: double

public double Blue { get; init; }

Green

The green channel.

Type: double

public double Green { get; init; }

Red

The red channel.

Type: double

public double Red { get; init; }

Methods

Dynamic

A color that resolves per appearance: light normally, dark in dark mode.

public static Color Dynamic(
  Color light,
  Color dark)
ParameterSummary
Color lightThe color used in light mode.
Color darkThe color used in dark mode.

Returns

  • Color: The appearance-aware color.

FromBytes

Creates a color from 8-bit channel values (0..255).

public static Color FromBytes(
  byte red,
  byte green,
  byte blue,
  byte alpha = 255)
ParameterSummary
byte redThe red channel.
byte greenThe green channel.
byte blueThe blue channel.
(optional) byte alphaThe alpha channel.

Returns

  • Color: The color represented by the channel values.

FromHex

Creates a color from a packed 0xRRGGBB or 0xAARRGGBB hex value.

public static Color FromHex(
  uint hex)
ParameterSummary
uint hexThe packed color value.

Returns

  • Color: The color represented by the packed value.

WithAlpha

Returns this color with a different alpha (0..1).

public Color WithAlpha(
  double alpha)
ParameterSummary
double alphaThe replacement alpha channel.

Returns

  • Color: A copy with the replacement alpha.