I draw some text in a custom Label.
User can modify the label background, but the control shoud accomodate the text visibility in dependence of the specified background.
So, when the background is DARK I want to draw white foreground text, when its LIGHT I want BLACK foreground.
How to "understand" if the color is LIGHT or DARK?
Contrast with a Black or Dark Background While white text on a black background provides very high value contrast, it is less readable and causes greater eye fatigue than black text on a white background.
Save this answer. Show activity on this post. Foreground light blue, white, gray, yellow color texts are present. Colors that don't go with black color background are not visible.
Black backgrounds: High-chroma colors are best for black backgrounds because they offer a good contrast ratio without the eye fatigue (which occurs with white text on a black background).
Value refers to the lightness or darkness of a color. A light color is a tint. For example, pink is a tint of red. A dark color is called a shade.
A simple solution is to add the color componets of the background color and compare them to a threshold.
You might want to give blue a lower weight. 0.3*R+0.6*G+0.1*B
is a common choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With