Class ColorExtensions
A set of extensions for dealing with Microsoft.Xna.Framework.Color objects.
public static class ColorExtensions
- Inheritance
-
ColorExtensions
- Inherited Members
Methods
CopyAlpha(Color, Color)
Copies the alpha value from another color into this color and returns the result.
public static Color CopyAlpha(this Color color, Color other)
Parameters
color
ColorThe color.
other
ColorThe color to copy the alpha from.
Returns
- Color
The first color with the second color's alpha value.
Invert(Color)
Returns an inverted version of this color.
public static Color Invert(this Color color)
Parameters
color
ColorThe color to invert.
Returns
- Color
The inverted color.
Multiply(Color, Color)
Multiplies this color with another color and returns the result.
public static Color Multiply(this Color color, Color other)
Parameters
color
ColorThe first color.
other
ColorThe second color.
Returns
- Color
The two colors multiplied together.
ToHexStringRgb(Color, bool)
Returns the hexadecimal representation of this color as a string in the format #RRGGBB
, or optionally RRGGBB
, without the pound symbol.
The alpha channel is ignored.
public static string ToHexStringRgb(this Color color, bool hash = true)
Parameters
color
ColorThe color to convert.
hash
boolWhether a # should prepend the string.
Returns
- string
The resulting hex string.
ToHexStringRgba(Color, bool)
Returns the hexadecimal representation of this color as a string in the format #AARRGGBB
, or optionally AARRGGBB
, without the pound symbol.
public static string ToHexStringRgba(this Color color, bool hash = true)
Parameters
color
ColorThe color to convert.
hash
boolWhether a # should prepend the string.
Returns
- string
The resulting hex string.
ToHsl(Color)
Converts the given color
into HSL representation and returns the result as a value tuple with values between 0 and 1.
public static (float H, float S, float L) ToHsl(this Color color)
Parameters
color
ColorThe color to convert.
Returns
- (float H, float S, float L)
The resulting HSL color as a value tuple containing H, S and L, each between 0 and 1.
Remarks
This code is adapted from https://gist.github.com/mjackson/5311256.
ToHsv(Color)
Converts the given color
into HSV representation and returns the result as a value tuple with values between 0 and 1.
public static (float H, float S, float V) ToHsv(this Color color)
Parameters
color
ColorThe color to convert.
Returns
- (float H, float S, float L)
The resulting HSV color as a value tuple containing H, S and V, each between 0 and 1.
Remarks
This code is adapted from https://gist.github.com/mjackson/5311256.