GetClosestColor implemented
This commit is contained in:
parent
376253996e
commit
cac788b6a6
3 changed files with 22 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ global using System.Collections.Generic;
|
||||||
global using System.Linq;
|
global using System.Linq;
|
||||||
global using System.Text;
|
global using System.Text;
|
||||||
global using System.Threading.Tasks;
|
global using System.Threading.Tasks;
|
||||||
|
global using System.Drawing;
|
||||||
|
|
||||||
global using static Xorog.UniversalExtensions.UniversalExtensionsEnums;
|
global using static Xorog.UniversalExtensions.UniversalExtensionsEnums;
|
||||||
global using static Xorog.UniversalExtensions.Internal;
|
global using static Xorog.UniversalExtensions.Internal;
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,14 @@ internal static class Internal
|
||||||
return _timespan.ToString();
|
return _timespan.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
internal static int GetDiff(Color color, Color baseColor)
|
||||||
|
{
|
||||||
|
int a = color.A - baseColor.A,
|
||||||
|
r = color.R - baseColor.R,
|
||||||
|
g = color.G - baseColor.G,
|
||||||
|
b = color.B - baseColor.B;
|
||||||
|
return a * a + r * r + g * g + b * b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InternalSheduler
|
public class InternalSheduler
|
||||||
|
|
|
||||||
|
|
@ -492,6 +492,19 @@ public static class UniversalExtensions
|
||||||
return string.Concat(country.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
|
return string.Concat(country.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get closest Color to given Color
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="colorArray"></param>
|
||||||
|
/// <param name="baseColor"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Color GetClosestColor(List<Color> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StringExt
|
public static class StringExt
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue