ColorTryParse Method

Tries to parse a string to a Color without throwing any exception upon failures.
public static bool TryParse(
	string input,
	out Color result
)

Parameters

inputSystemString
The string to be parsed as a Color.
resultJdenticon.RenderingColor
The parsed color.

Return Value

Boolean
true if input could be parsed as a color, otherwise false.

Remarks

This method will parse all formats listed in the CSS 3 color specification except system colors and the currentColor keyword.

FormatExampleRemarks
#RGB#23fFully opaque color. Will be expanded to #2233ff.
#RGBA#23faShort RGB color with alpha value. Will be expanded to #2233ffaa.
#RRGGBB#2233ffFully opaque color.
#RRGGBBAA#2233ffaaRGB color with alpha value.
<named-color>firebrickSee list of supported color keywords in CSS 3 color specification.
'transparent'transparentFully transparent black.
rgb(red, green, blue)rgb(0, 128, 255)Fully opaque RGB color in decimal format.
rgba(red, green, blue, alpha)rgba(0, 128, 255, 0.5)RGB color with alpha value. RGB components specified in decimal format and alpha as a floating point number in the range [0, 1].
hsl(hue, saturation, lightness)hsl(120, 75%, 75%)Fully opaque Hue-Saturation-Lightness color. Hue specified in degrees, saturation and lightness in percents.
hsla(hue, saturation, lightness, alpha)hsla(120, 75%, 75%, 0.5)Hue-Saturation-Lightness color with alpha value. Hue specified in degrees, saturation and lightness in percents.

In addition to the formats listed above some of the formats listed in the CSS Color Module Level 4 specification are supported.

Caution note Caution

The following formats are considered experimental and can change at any time without causing a major release of Jdenticon.

FormatExampleRemarks
rgb(red, green, blue, alpha)rgb(0, 128, 255, 0.5)RGB color with alpha value. RGB components specified in decimal format and alpha as a floating point number in the range [0, 1].
hsl(hue, saturation, lightness, alpha)hsl(120, 75%, 75%, 0.5)Hue-Saturation-Lightness color with alpha value. Hue specified in degrees, saturation and lightness in percents.
hsl(hue, saturation, lightness, alpha)hsl(120deg, 75%, 75%, 0.5)Same as above, but with explicit unit for the hue - degrees, range: [0, 360].
hsl(hue, saturation, lightness, alpha)hsl(120rad, 75%, 75%, 0.5)Same as above, but with hue specified in radians, range: [0, 2π).
hsl(hue, saturation, lightness, alpha)hsl(120turn, 75%, 75%, 0.5)Same as above, but with hue specified in turns, range: [0, 1).
hsl(hue, saturation, lightness, alpha)hsl(120grad, 75%, 75%, 0.5)Same as above, but with hue specified in gradians, range: [0, 400).
hwb(hue, whiteness, blackness[, alpha])hwb(120, 75%, 75%, 0.5)Hue-Whiteness-Blackness color with optional alpha value. Hue specified in degrees, or in any of the units available for hsl(), the whiteness and blackness in percent.

See Also

Reference