PeterO.ColorValidator
PeterO.ColorValidator
public static class ColorValidator
Contains methods to convert between different representations of HTML and CSS colors.
ColorHtmlToRgba
public static double[] ColorHtmlToRgba(
string x);
Converts HTML colors to Red/Green/Blue colors.
Parameters:
- x: A string in the form of an HTML color or CSS color name (ex. #223344, #234, or royalblue).All strings are treated as valid.Returns a 4-element array containing the red, green, blue, and alpha(each 0-255); the alpha is always 255..
Return Value:
An array of four elements, each from 0 to 255: the red, green, blue, and alpha components, in that order.
Exceptions:
- System.ArgumentNullException: The parameter x is null.
ColorToRgb
public static double[] ColorToRgb(
string x);
Converts HTML colors to Red/Green/Blue colors. Use this function to parse colors from normal color picker controls: http://peteroupc.github.com/colorpicker/.
Parameters:
- x: A string object.
Return Value:
A double[] object.
ColorToRgba
public static double[] ColorToRgba(
string x);
Not documented yet.
Parameters:
- x: Not documented yet.
Return Value:
Not documented yet.
HlsToRgb
public static double[] HlsToRgb(
double[] hls);
Converts a color in the HLS color space to red/green/blue.
Parameters:
- hls: An array containing three elements: The first is the hue, in degrees, ranging from 0 through 360; the second is the luminosity (luminance or lightness), ranging from 0 to 255; and the third is the saturation, ranging from 0 to 255.
Return Value:
An array of three elements, each from 0 to 255: the red, green, and blue components, in that order.
Exceptions:
- System.ArgumentNullException: The parameter hls is null.
RgbToColor
public static string RgbToColor(
double[] arrayRGB);
Converts an RGBA color to a string, either rgb(...) or rgba(...) as applicable.
Parameters:
- arrayRGB: A double[] object.
Return Value:
A string object.
Exceptions:
- System.ArgumentNullException: The parameter arrayRGB is null.
RgbToColorDisplay
public static string RgbToColorDisplay(
double[] rgb);
Converts a red–green–blue-alpha color to a string in CSS format.
Parameters:
- rgb: A double[] object.
Return Value:
A string object.
Exceptions:
System.ArgumentException: The parameter rgb is null or contains fewer than three elements.
System.ArgumentNullException: The parameter rgb is null.
RgbToColorHtml
public static string RgbToColorHtml(
double r,
double g,
double b);
Converts a red–green–blue color to a string in HTML format.
Parameters:
r: A 64-bit floating-point number.
g: Another 64-bit floating-point number.
b: A 64-bit floating-point number. (3).
Return Value:
A string object.
RgbToColorHtml
public static string RgbToColorHtml(
double[] rgb);
Converts an RGBA color to an HTML color, (ex. #002233)."rgb" must contain at least 3 elements: the red, green, and blue (each 0-255).
Parameters:
- rgb: A double[] object.
Return Value:
A string object.
Exceptions:
- System.ArgumentNullException: The parameter rgb is null.