Convertir les couleurs HSB en RGB et réciproquement

Voici un code qui vous permettra de convertir les couleurs au format HSB vers le format RGB et inversement :

package com.supinfo.codesample.colorconvert;
import java.awt.Color;

public final class ColorConvert {
public static void rgbToHsb (int r, int g, int b){
// Convert RGB => HSB
float[] hsb = Color.RGBtoHSB(r, g, b, null);
float hue = hsb[0];
float sat = hsb[1];
float bri = hsb[2];

System.out.println("H : " + hue + " S : " + sat + " B : " + bri);
}

public static void hsbToRgb (float h, float s, float b){
// Convert HSB => RGB
int rgb = Color.HSBtoRGB(h, s, b);
int red = (rgb>>16)&0xFF;
int green = (rgb>>8)&0xFF;
int blue = rgb&0xFF;
System.out.println("R : " + red + " G : " + green + " B : " + blue);
}

public static void main(String [] args){
rgbToHsb(255,10,10);
hsbToRgb(0.1f, 0.3f, 0.6F);
}
}

Laboratoire SUPINFO des technologies Sun
labo-sun@supinfo.com


Conditions d'utilisation et © Copyright 2000-2006 SUPINFO Paris, Paris Academy of Computer Science
23, rue de Château Landon - 75010 PARIS - Tél : +33 (0) 153359700 Fax : +33 (0) 153359701
Respect de la vie privée