|
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);
}
}
|