Convert colors in RGB to HLS and vice versa.
![]()
RGB doesn’t need and introduction and If you are experienced in adobe photoshop, then you might be already familiar with HLS too.
RGB
All of us know about RGB. RGB is a color space in which, colors are represented by Red, Green and Blue components. Each component can vary from 0-255 in value. See the RGB color space below. (Thanks to MSDN for the pic)

HLS
HLS is also a Color space similar to RGB. But instead of red, green and blue components, HLS contain Hue, Luminance & Saturation components. Its a color space in which the Hue, saturation and luminance of a color can be separated and modified. See the HLS color space below.( Thanks to Wiki for the pic. )

![]()
Well, how can you convert RGB color to HLS and vice versa? You can use the api’s – ColorRGBToHLS() and ColorHLSToRGB(). See the sample code snippet below.
#include "Shlwapi.h" ... // Red color in RGB COLORREF RgbColor = RGB( 255, 0, 0 ); // Convert to HLS Color space WORD Hue = 0; WORD Luminance = 0; WORD Saturation = 100; ColorRGBToHLS( RgbColor, &Hue, &Luminance, &Saturation ); // Its converted to Hue, Luminance and Saturation. // You can adjust the parameters according to your wish. // Now convert back to RGB. RgbColor = ColorHLSToRGB( Hue, Luminance, Saturation );
![]()
You can generate a wide variety of effects by adjusting HLS parameters which cannot be done by using RGB. Designers always use these HLS components for generating creative images. Take Photoshop and have a try!
BTW, don’t forget to add Shlwapi.lib to project settings.
![]()
Targeted Audience – Intermediate.
[...] There is another method to convert an image to grayscale – By using HLS colorspace. I’ve already explaned about HLS color space here – http://weseetips.com/2008/05/22/convert-color-in-rgb-to-hls-and-vice-versa/ [...]
So, can you please provide a tutorial to create the vista type glass appearence for controls and windows in XP? transparency can be achieved in windows XP but, i need that vista model transparency when the aero is enabled. i need only Win32, no MFC… thankz