namespace Xorog.UniversalExtensions;
public static class ColorTools
{
///
/// Get closest Color to given Color
///
///
///
///
public static Color GetClosestColor(List colorArray, Color baseColor)
{
var colors = colorArray.Select(x => new { Value = x, Diff = Internal.GetDiff(x, baseColor) }).ToList();
var min = colors.Min(x => x.Diff);
return colors.Find(x => x.Diff == min).Value;
}
///
/// Convert Hex to Color
///
/// The converted color
public static Color ToColor(this string str)
{
return ColorTranslator.FromHtml(str);
}
///
/// Convert RGB Value to Hex
///
/// Red
/// Green
/// Blue
/// A string that represents the color in hex (e.g. 255, 0, 0 -> #FF0000)
public static string ToHex(int R, int G, int B)
{
return "#" + R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
}
}