SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[FEATURE] Get SKColor from color name

Open ashahabov opened this issue 2 years ago • 1 comments

Description

As a SkiaSharp user, I want to be able to get SKColor instance from the input string which is a color name.

It can be, for example, a new .FromName() method:

var inputClrName = "blue";
var color = SKColor.FromName(inputClrName);

Additional context

Initial discussion: https://github.com/mono/SkiaSharp/discussions/2250

ashahabov avatar Sep 12 '22 21:09 ashahabov

Is this function part of Skia? If not then it shouldn't be added. You can use any string to Color? function (there is one in System.Drawing.Color) and then convert to SKColor.

charlesroddie avatar Sep 19 '22 21:09 charlesroddie

System.Drawing.Color causes major problems in linux due to its utilization of libdgiplus and its not available for every linux distro. so may be an alternative is var color = SKColor.FromName(inputClrName); if available

uxmanz avatar Nov 29 '22 12:11 uxmanz

Hi guys, any news on it?

JakNo avatar Jul 17 '23 07:07 JakNo

here is a sample:

private static SKColor GetColor(string colorName) { var skColor = typeof(SKColors).GetField(colorName); if (skColor != null) { return (SKColor)skColor.GetValue(null)!; } return SKColors.Black; }

nchabelengmc avatar Aug 14 '23 15:08 nchabelengmc