I'm not sure how to ask about it, but here it goes.
I draw a filled color rectangle on the screen. The color has the form R, G, B
Then I want to draw the text on top of the rectangle, however, the color of the text should be such that it provides better contrast, that is, readable.
Example:
If I draw a black rectangle, the obvious color of the text will be white.
What I tried right now is this. I pass this function the color of the rectangle and returns the inverted color, which I then use for my text.
It works, but it is not the best way.
Any suggestions?
// eg. usage: Color textColor = GetInverseLuminance(rectColor); private Color GetInverseLuminance(Color color) { int greyscale = (int)(255 - ((color.R * 0.30f) + (color.G * 0.59f) + (color.B * 0.11f))); return Color.FromArgb(greyscale, greyscale, greyscale); }
source share