Skip to content
January 3, 2010 / lawrencebarsanti

Lighten colors programmatically with Delphi

Many people understand that computers store colors as RGB values and that a value like 770000 represents a dark shade of red.  However, RGB values are hard to manipulate in a meaningful way (like brightening a color).  That is where the HSL color space comes in handy.  In the HSL color space, colors are represented by there Hue, Saturation, and Luminance.  The image below shows the full range of Saturation (horizontal axis) and Luminance (vertical axis) when the Hue is fixed at an arbitrary blue value.blueOnce you understand how saturation and luminance affect a hue, you can manipulate these values to produce colors that work well together.  For example, the background of the interior boxes in the simple counters shown below were created by adjusting the luminance of the outer box.


The following code was used to do brighten the main color.  The functions  ColorHLSToRGB and ColorRGBToHSL are defined in the unit GraphUtil.

function Brighten(AColor: TColor): TColor; 
  H, S, L: Word; 
  ColorRGBToHLS(AColor, H, L, S); 
  Result := ColorHLSToRGB(H, 225, S); 

Warning: this code assumes AColor will have a low luminance value.


One Comment

Leave a Comment
  1. Jackob Oram / Oct 18 2010 11:17 am

    Fantastic! congratulations for your work and ideas.
    Thank You
    Delphi Application Migration

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: