Created
October 15, 2020 17:49
-
-
Save timheuer/1ac4d5167a49d4803d2e6c84f6f8c062 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Colors | |
{ | |
private const string COLOR_WHITE = "white"; | |
private const string COLOR_BLACK = "black"; | |
public static string GetReadableForeColorAsString(string backgroundColor) | |
{ | |
// turn the background color into Color obj | |
var c = ColorTranslator.FromHtml($"#{backgroundColor}"); | |
// calculate best foreground color | |
return (((c.R + c.B + c.G) / 3) > 128) ? COLOR_BLACK : COLOR_WHITE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment