November 02, 2004

SWT Colors in HSB Space

Just in time for election day, here’s a snippet of code that performs a manipulation of the value dimension of an SWT color:

private Color colorWithValue(Color c, float value)
{
    RGB rgb = c.getRGB();
    float[] fs = 
      java.awt.Color.RGBtoHSB(rgb.red, rgb.green, rgb.blue, null);
    java.awt.Color cc = 
      new java.awt.Color(java.awt.Color.HSBtoRGB(fs[0], fs[1], value));
    return new Color(getDisplay(), cc.getRed(), cc.getGreen(), cc.getBlue());		
}
Posted by MrFeinberg at November 2, 2004 12:39 PM
Comments