Class ColorExtensions
Provides extension methods for SKColor to support hexadecimal color codes.
Inherited Members
Namespace: OpenSvg
Assembly: OpenSvg.dll
Syntax
public static class ColorExtensions
Properties
| Edit this page View SourceTransparent
Gets a SKColor that represents the transparent color.
Declaration
public static SKColor Transparent { get; }
Property Value
Type | Description |
---|---|
SKColor |
Methods
| Edit this page View SourceIsTransparent(SKColor)
Returns whether the specified SKColor is transparent.
Declaration
public static bool IsTransparent(this SKColor sKColor)
Parameters
Type | Name | Description |
---|---|---|
SKColor | sKColor | The SKColor instance to check. |
Returns
Type | Description |
---|---|
bool |
|
ToColor(string)
Parses a hexadecimal color string and returns the corresponding SKColor.
Declaration
public static SKColor ToColor(this string colorString)
Parameters
Type | Name | Description |
---|---|---|
string | colorString | The hexadecimal color string to parse. |
Returns
Type | Description |
---|---|
SKColor | A SKColor instance that corresponds to the given hexadecimal color string. |
Remarks
The method accepts color strings in the following formats:
- Hexadecimal RGB: Starts with a '#' followed by 6 hexadecimal characters (e.g., "#FF0000" for red).
- Transparent: The string "none" to indicate a transparent color.
- Named colors: Colors defined in SkiaSharp (e.g., "Red", "LightSkyBlue") are also supported.
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when the specified string is null, empty, or has an invalid format. |
ToHexColorString(SKColor)
Returns a hexadecimal representation of the given SKColor.
Declaration
public static string ToHexColorString(this SKColor color)
Parameters
Type | Name | Description |
---|---|---|
SKColor | color | The SKColor instance to be converted. |
Returns
Type | Description |
---|---|
string | A hexadecimal string that represents the given color. |
ToString(SKColor)
Returns a string representation of the given SKColor.
Declaration
public static string ToString(this SKColor color)
Parameters
Type | Name | Description |
---|---|---|
SKColor | color | The SKColor instance to be converted. |
Returns
Type | Description |
---|---|
string | A string that represents the given color. |