Skip to content

Calculating Color Brightness

gchudnov edited this page Dec 18, 2014 · 1 revision

To determine whether you should be using white or black text depending on the background color, calculate the color brightness:

  color c1 = boost::lexical_cast<color>(L"#ffef4444");
  auto value = brightness(c1); // value == brightness_value::dark

The returned brightness value gives a perceived brightness for a color.

To ensure that the text is visible on the background of a given color, select white for brightness_value::dark and black for brightness_value::light.

Clone this wiki locally