Struct HslColor
Defines a color using the hue/saturation/lightness (HSL) model. This uses a cylindrical-coordinate representation of a color.
public readonly struct HslColor : IEquatable<HslColor>
- Implements
- Inherited Members
Constructors
HslColor(Color)
Initializes a new instance of the HslColor struct.
public HslColor(Color color)
Parameters
color
ColorThe RGB color to convert to HSL.
HslColor(double, double, double, double)
Initializes a new instance of the HslColor struct.
public HslColor(double alpha, double hue, double saturation, double lightness)
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.
lightness
doubleThe Lightness 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.
L
Gets the Lightness component in the range from 0..1 (percentage).
public double L { get; }
Property Value
Remarks
- 0 is fully black.
- 1 is fully white.
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.
Methods
Equals(HslColor)
public bool Equals(HslColor other)
Parameters
other
HslColor
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
FromAhsl(double, double, double, double)
Creates a new HslColor from individual color component values.
public static HslColor FromAhsl(double a, double h, double s, double l)
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.
l
doubleThe Lightness 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.
FromHsl(double, double, double)
Creates a new HslColor from individual color component values.
public static HslColor FromHsl(double h, double s, double l)
Parameters
h
doubleThe Hue component in the range from 0..360.
s
doubleThe Saturation component in the range from 0..1.
l
doubleThe Lightness 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 HSL color string.
public static HslColor Parse(string s)
Parameters
s
stringThe HSL color string to parse.
Returns
ToHsv()
Returns the HSV color model equivalent of this HSL color.
public HsvColor ToHsv()
Returns
- HsvColor
The HSV equivalent color.
ToHsv(double, double, double, double)
Converts the given HSLA color component values to their HSV color equivalent.
public static HsvColor ToHsv(double hue, double saturation, double lightness, double alpha = 1)
Parameters
hue
doubleThe Hue component in the HSL color model in the range from 0..360.
saturation
doubleThe Saturation component in the HSL color model in the range from 0..1.
lightness
doubleThe Lightness component in the HSL 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 HSL color.
public Color ToRgb()
Returns
- Color
The RGB equivalent color.
ToRgb(double, double, double, double)
Converts the given HSLA color component values to their RGB color equivalent.
public static Color ToRgb(double hue, double saturation, double lightness, double alpha = 1)
Parameters
hue
doubleThe Hue component in the HSL color model in the range from 0..360.
saturation
doubleThe Saturation component in the HSL color model in the range from 0..1.
lightness
doubleThe Lightness component in the HSL 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 HslColor)
Parses an HSL color string.
public static bool TryParse(string? s, out HslColor hslColor)
Parameters
Returns
- bool
True if parsing was successful; otherwise, false.
Operators
operator ==(HslColor, HslColor)
Indicates whether the values of two specified HslColor objects are equal.
public static bool operator ==(HslColor left, HslColor right)
Parameters
Returns
- bool
True if left and right are equal; otherwise, false.
explicit operator Color(HslColor)
public static explicit operator Color(HslColor hslColor)
Parameters
Returns
operator !=(HslColor, HslColor)
Indicates whether the values of two specified HslColor objects are not equal.
public static bool operator !=(HslColor left, HslColor right)
Parameters
Returns
- bool
True if left and right are not equal; otherwise, false.