Class ColorHelper
A set of utility methods for dealing with Microsoft.Xna.Framework.Color objects.
public static class ColorHelper
- Inheritance
-
ColorHelper
- Inherited Members
Methods
FromHexRgb(int)
Parses a hexadecimal number into an rgb color with 100% alpha.
The number should be in the format 0xrrggbb
.
public static Color FromHexRgb(int value)
Parameters
value
intThe number to parse.
Returns
- Color
The resulting color.
FromHexRgba(int)
Parses a hexadecimal number into an rgba color.
The number should be in the format 0xaarrggbb
.
public static Color FromHexRgba(int value)
Parameters
value
intThe number to parse.
Returns
- Color
The resulting color.
FromHexString(string)
Parses a hexadecimal string into a color and throws a FormatException if parsing fails.
The string can either be formatted as RRGGBB
or AARRGGBB
and can optionally start with a #
.
public static Color FromHexString(string value)
Parameters
value
stringThe string to parse.
Returns
- Color
The resulting color.
Exceptions
- FormatException
Thrown if parsing fails.
FromHsl(float, float, float)
Converts the given HSL values to an RGB Microsoft.Xna.Framework.Color and returns the result.
public static Color FromHsl(float h, float s, float l)
Parameters
h
floatThe H component of the HSL color, between 0 and 1.
s
floatThe S component of the HSL color, between 0 and 1.
l
floatThe L component of the HSL color, between 0 and 1.
Returns
- Color
The resulting RGB color.
Remarks
This code is adapted from https://gist.github.com/mjackson/5311256.
FromHsl((float H, float S, float L))
Converts the given HSL color to an RGB Microsoft.Xna.Framework.Color and returns the result.
public static Color FromHsl((float H, float S, float L) color)
Parameters
color
(float H, float S, float L)The HSL color to convert, as a value tuple that contains H, S and L values, each between 0 and 1.
Returns
- Color
The resulting RGB color.
Remarks
This code is adapted from https://gist.github.com/mjackson/5311256.
FromHsv(float, float, float)
Converts the given HSV values to an RGB Microsoft.Xna.Framework.Color and returns the result.
public static Color FromHsv(float h, float s, float v)
Parameters
h
floatThe H component of the HSV color, between 0 and 1.
s
floatThe S component of the HSV color, between 0 and 1.
v
floatThe V component of the HSV color, between 0 and 1.
Returns
- Color
The resulting RGB color.
Remarks
This code is adapted from https://gist.github.com/mjackson/5311256.
FromHsv((float H, float S, float V))
Converts the given HSV color to an RGB Microsoft.Xna.Framework.Color and returns the result.
public static Color FromHsv((float H, float S, float V) color)
Parameters
color
(float H, float S, float L)The HSV color to convert, as a value tuple that contains H, S and V values, each between 0 and 1.
Returns
- Color
The resulting RGB color.
Remarks
This code is adapted from https://gist.github.com/mjackson/5311256.
TryFromHexString(string, out Color)
Tries to parse a hexadecimal string into a color and returns whether a color was successfully parsed.
The string can either be formatted as RRGGBB
or AARRGGBB
and can optionally start with a #
.
public static bool TryFromHexString(string value, out Color color)
Parameters
value
stringThe string to parse.
color
ColorThe resulting color.
Returns
- bool
Whether parsing was successful.