If you need a portable .NET solution for converting RGB to HLS and vice versa there are libraries around to do it. For Windows only using the Shell Lightweight Utility Functions is a simpler alternative.

  1. [DllImport("shlwapi.dll")]  
  2. static extern int ColorHLSToRGB(int H, int L, int S);  
  3. [DllImport("shlwapi.dll")]  
  4. static extern void ColorRGBToHLS(int RGB, ref int H, ref int L, ref int S);  
  5. // RGB2HLS  
  6. ColorRGBToHLS(ColorTranslator.ToWin32(rgbColor, ref h, ref l, ref s);  
  7. // HLS2RGB  
  8. Color rgbColor=ColorTranslator.FromWin32(ColorHLSToRGB(h, l, s));  

0 comment(s) :

Newer Post Older Post Home

Blogger Syntax Highliter