How convert SixLabors.ImageSharp.Color to System.Drawing.Color?

1.3k views Asked by At

I need to convert instance of SixLabors.ImageSharp.Color to System.Drawing.Color and backwards. How to do it?

1

There are 1 answers

0
Kemsikov On

Just added extensions:

using SixLabors.ImageSharp.PixelFormats;
    public static class ColorExtensions
    {
        public static System.Drawing.Color ToSystemDrawingColor(this SixLabors.ImageSharp.Color c){
            var converted = c.ToPixel<Argb32>();
            return System.Drawing.Color.FromArgb((int)converted.Argb);
        }
        public static SixLabors.ImageSharp.Color ToImageSharpColor(this System.Drawing.Color c){
            return SixLabors.ImageSharp.Color.FromRgba(c.R,c.G,c.B,c.A);
        }
    }