File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11namespace DevWinUI ;
22public static partial class Extensions
33{
4+ /// <summary>
5+ /// Finds the best contrasting color (black or white)
6+ /// </summary>
7+ /// <param name="color"></param>
8+ /// <returns></returns>
9+ public static Color ContrastColorBlackWhite ( this Color color )
10+ {
11+ return ColorHelper . ContrastColorBlackWhite ( color ) ;
12+ }
13+
414 /// <summary>
515 /// Converts a hexadecimal color string into a SolidColorBrush object.
616 /// </summary>
Original file line number Diff line number Diff line change @@ -274,4 +274,15 @@ public static float GetSaturationFromColor(Color color)
274274
275275 return saturation ;
276276 }
277+
278+ /// <summary>
279+ /// Finds the best contrasting color (black or white)
280+ /// </summary>
281+ /// <param name="color"></param>
282+ /// <returns></returns>
283+ public static Color ContrastColorBlackWhite ( Color color )
284+ {
285+ double luma = ( ( 0.299 * color . R ) + ( 0.587 * color . G ) + ( 0.114 * color . B ) ) / ( double ) 255 ;
286+ return luma > 0.5 ? Colors . Black : Colors . White ;
287+ }
277288}
You can’t perform that action at this time.
0 commit comments