Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colors: White if background is DARK and BLACK when is LIGHT

Tags:

.net

gdi+

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?

like image 763
serhio Avatar asked Jun 21 '11 10:06

serhio


People also ask

Is it easier to see white on black or black on white?

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.

What color is visible on black and 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.

Which color looks best on black background?

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).

How can you tell if a color is dark or light?

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.


1 Answers

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.

like image 98
CodesInChaos Avatar answered Sep 26 '22 14:09

CodesInChaos