Struct HsvColor
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
ColorThe 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
doubleThe Alpha (transparency) component in the range from 0..1.
hue
doubleThe Hue component in the range from 0..360. Note that 360 is equivalent to 0 and will be adjusted automatically.
saturation
doubleThe Saturation component in the range from 0..1.
value
doubleThe 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
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
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
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
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
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
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
doubleThe Alpha (transparency) component in the range from 0..1.
h
doubleThe Hue component in the range from 0..360.
s
doubleThe Saturation component in the range from 0..1.
v
doubleThe Value component in the range from 0..1.
Returns
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
doubleThe Hue component in the range from 0..360.
s
doubleThe Saturation component in the range from 0..1.
v
doubleThe Value component in the range from 0..1.
Returns
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
stringThe HSV color string to parse.
Returns
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
doubleThe Hue component in the HSV color model in the range from 0..360.
saturation
doubleThe Saturation component in the HSV color model in the range from 0..1.
value
doubleThe Value component in the HSV color model in the range from 0..1.
alpha
doubleThe Alpha component in the range from 0..1.
Returns
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
doubleThe Hue component in the HSV color model in the range from 0..360.
saturation
doubleThe Saturation component in the HSV color model in the range from 0..1.
value
doubleThe Value component in the HSV color model in the range from 0..1.
alpha
doubleThe Alpha component in the range from 0..1.
Returns
ToString()
public override string ToString()
Returns
TryParse(string?, out HsvColor)
Parses an HSV color string.
public static bool TryParse(string? s, out HsvColor hsvColor)
Parameters
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
Returns
- bool
True if left and right are equal; otherwise, false.
explicit operator Color(HsvColor)
public static explicit operator Color(HsvColor hsvColor)
Parameters
Returns
operator !=(HsvColor, HsvColor)
Indicates whether the values of two specified HsvColor objects are not equal.
public static bool operator !=(HsvColor left, HsvColor right)
Parameters
Returns
- bool
True if left and right are not equal; otherwise, false.