title: How to calculate easy to read color for a random backcolor?
body: <p>in my current tool there is a colored box with some numbers in it. The backcolor of the box is defined by some sort of list but can also be altered by the user. The forecolor (== fontcolor of the numbers) cannot, and i want to make sure that the user can always read the numbers, so i´d like to adjust the forecolor of the numbers anytime the backcolor changes.</p>
  
  <p>Atm i use code like this:</p>
  
  <pre><code>if(Math.Abs(foreColor.GetBrightness() - backColor.GetBrightness()) &lt;= 0.5f)
  {
      if(foreColor.GetBrightness() &gt; 0.5f)
      {
         foreColor = Color.Black;
      }
      else
      {
         foreColor = Color.White;
      }
  }
  </code></pre>
  
  <p>but that is only a workaround for the problem, there are quite a lot of colors (mostly yellows) leading to a bad to read display. Anyone touched a similar problem and found a good solution?</p>