42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Media;
|
|
|
|
namespace Chrosey.Extensions
|
|
{
|
|
public static class ColorExtensions
|
|
{
|
|
public static Color ToColor(this Brush brush)
|
|
{
|
|
var result = ColorConverter.ConvertFromString(brush.ToString());
|
|
if (null != result)
|
|
{
|
|
return (Color)result;
|
|
}
|
|
return Colors.Transparent;
|
|
}
|
|
public static Color AsColor(this string colorString)
|
|
{
|
|
|
|
var result = ColorConverter.ConvertFromString(colorString);
|
|
if (null != result)
|
|
{
|
|
return (Color)result;
|
|
}
|
|
return Colors.Transparent;
|
|
}
|
|
|
|
public static System.Drawing.Color SignificantColor(this System.Drawing.Color input)
|
|
{
|
|
var shiftBits = 3;
|
|
var r = Convert.ToByte(input.R >> shiftBits);
|
|
var g = Convert.ToByte(input.G >> shiftBits);
|
|
var b = Convert.ToByte(input.B >> shiftBits);
|
|
return System.Drawing.Color.FromArgb(r << shiftBits, g << shiftBits, b << shiftBits);
|
|
}
|
|
}
|
|
}
|