Table of Contents

Struct HsvColor

Namespace
Avalonia.Media
Assembly
Avalonia.Base.dll

Defines a color using the hue/saturation/value (HSV) model. This uses a cylindrical-coordinate representation of a color.

public readonly struct HsvColor : IEquatable<HsvColor>
Implements
Inherited Members

Constructors

HsvColor(Color)

Initializes a new instance of the HsvColor struct.

public HsvColor(Color color)

Parameters

color Color

The RGB color to convert to HSV.

HsvColor(double, double, double, double)

Initializes a new instance of the HsvColor struct.

public HsvColor(double alpha, double hue, double saturation, double value)

Parameters

alpha double

The Alpha (transparency) component in the range from 0..1.

hue double

The Hue component in the range from 0..360. Note that 360 is equivalent to 0 and will be adjusted automatically.

saturation double

The Saturation component in the range from 0..1.

value double

The Value component in the range from 0..1.

Properties

A

Gets the Alpha (transparency) component in the range from 0..1 (percentage).

public double A { get; }

Property Value

double

Remarks

  • 0 is fully transparent.
  • 1 is fully opaque.

H

Gets the Hue component in the range from 0..360 (degrees). This is the color's location, in degrees, on a color wheel/circle from 0 to 360. Note that 360 is equivalent to 0 and will be adjusted automatically.

public double H { get; }

Property Value

double

Remarks

  • 0/360 degrees is Red.
  • 60 degrees is Yellow.
  • 120 degrees is Green.
  • 180 degrees is Cyan.
  • 240 degrees is Blue.
  • 300 degrees is Magenta.

S

Gets the Saturation component in the range from 0..1 (percentage).

public double S { get; }

Property Value

double

Remarks

  • 0 is fully white (or a shade of gray) and shows no color.
  • 1 is the full color.

V

Gets the Value (or Brightness/Intensity) component in the range from 0..1 (percentage).

public double V { get; }

Property Value

double

Remarks

  • 0 is fully black and shows no color.
  • 1 is the brightest and shows full color.

Methods

Equals(HsvColor)

public bool Equals(HsvColor other)

Parameters

other HsvColor

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

FromAhsv(double, double, double, double)

Creates a new HsvColor from individual color component values.

public static HsvColor FromAhsv(double a, double h, double s, double v)

Parameters

a double

The Alpha (transparency) component in the range from 0..1.

h double

The Hue component in the range from 0..360.

s double

The Saturation component in the range from 0..1.

v double

The Value component in the range from 0..1.

Returns

HsvColor

A new HsvColor built from the individual color component values.

Remarks

This exists for symmetry with the Color struct; however, the appropriate constructor should commonly be used instead.

FromHsv(double, double, double)

Creates a new HsvColor from individual color component values.

public static HsvColor FromHsv(double h, double s, double v)

Parameters

h double

The Hue component in the range from 0..360.

s double

The Saturation component in the range from 0..1.

v double

The Value component in the range from 0..1.

Returns

HsvColor

A new HsvColor built from the individual color component values.

Remarks

This exists for symmetry with the Color struct; however, the appropriate constructor should commonly be used instead.

GetHashCode()

Gets a hashcode for this object. Hashcode is not guaranteed to be unique.

public override int GetHashCode()

Returns

int

The hashcode for this object.

Parse(string)

Parses an HSV color string.

public static HsvColor Parse(string s)

Parameters

s string

The HSV color string to parse.

Returns

HsvColor

The parsed HsvColor.

ToHsl()

Returns the HSL color model equivalent of this HSV color.

public HslColor ToHsl()

Returns

HslColor

The HSL equivalent color.

ToHsl(double, double, double, double)

Converts the given HSVA color component values to their HSL color equivalent.

public static HslColor ToHsl(double hue, double saturation, double value, double alpha = 1)

Parameters

hue double

The Hue component in the HSV color model in the range from 0..360.

saturation double

The Saturation component in the HSV color model in the range from 0..1.

value double

The Value component in the HSV color model in the range from 0..1.

alpha double

The Alpha component in the range from 0..1.

Returns

HslColor

A new HslColor equivalent to the given HSVA values.

ToRgb()

Returns the RGB color model equivalent of this HSV color.

public Color ToRgb()

Returns

Color

The RGB equivalent color.

ToRgb(double, double, double, double)

Converts the given HSVA color component values to their RGB color equivalent.

public static Color ToRgb(double hue, double saturation, double value, double alpha = 1)

Parameters

hue double

The Hue component in the HSV color model in the range from 0..360.

saturation double

The Saturation component in the HSV color model in the range from 0..1.

value double

The Value component in the HSV color model in the range from 0..1.

alpha double

The Alpha component in the range from 0..1.

Returns

Color

A new RGB Color equivalent to the given HSVA values.

ToString()

public override string ToString()

Returns

string

TryParse(string?, out HsvColor)

Parses an HSV color string.

public static bool TryParse(string? s, out HsvColor hsvColor)

Parameters

s string

The HSV color string to parse.

hsvColor HsvColor

The parsed HsvColor.

Returns

bool

True if parsing was successful; otherwise, false.

Operators

operator ==(HsvColor, HsvColor)

Indicates whether the values of two specified HsvColor objects are equal.

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

Parameters

left HsvColor

The first object to compare.

right HsvColor

The second object to compare.

Returns

bool

True if left and right are equal; otherwise, false.

explicit operator Color(HsvColor)

Explicit conversion from an HsvColor to a Color.

public static explicit operator Color(HsvColor hsvColor)

Parameters

hsvColor HsvColor

The HsvColor to convert.

Returns

Color

operator !=(HsvColor, HsvColor)

Indicates whether the values of two specified HsvColor objects are not equal.

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

Parameters

left HsvColor

The first object to compare.

right HsvColor

The second object to compare.

Returns

bool

True if left and right are not equal; otherwise, false.