Skip to main content
1 of 6
Mark
  • 143
  • 3

Best Way to Darken a Color Until Its Readable

Whats the best way to darken a color until it is readable? I have a series of titles are have an associated color, but some of these colors are very light and any text drawn in them is unreadable. I've been messing around with HSB and I can't seem to get an algorithm down that darkens the color without making it look silverish.

I've basically just been doing this, but it doesn't seem to get what I would call "good" results. This is C# code if that relevant:

Color c =  
  FromHSB(
    orig.A,
    orig.GetHue(),
    orig.GetSaturation(),
    orig.GetBrightness() > .9 ?
      orig.GetBrightness() - MyClass.Random(.5, .10)
      : orig.GetBrightness());

I think I want to alter the saturation too. Is there a standard way of doing this?

Mark
  • 143
  • 3