/*
Convert RGB To HSB Color Example
This java example shows how to convert Red,Green, and Blue (RGB) to
Hue, Saturation, and brightness model (HSB) using Java AWT Color class.
*/
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
/*
<applet code="ConvertRGBToHSBColor" width=400 height=100>
</applet>
*/
public class ConvertRGBToHSBColor extends Applet{
public void paint(Graphics g){
/*
* To convert RGB to HSB, use
* static float[] RGBtoHSB(int r, int g, int b, float[] hsbValues)
* method of AWT Color class.
*
* This method converts RGB components to it's equivalent HSB values.
*
* If hsbValues array is null, new array will be created and returned,
* otherwise the same array will be returned with the HSB values.
*
* This method returns an array of three elements having hue at first index,
* saturation at second and brightness at third index.
* .
*/
float[] hsbValues = new float[3];
hsbValues = Color.RGBtoHSB(255,10,10,hsbValues);
float hue, saturation, brightness;
hue = hsbValues[0];
saturation = hsbValues[1];
brightness = hsbValues[2];
g.drawString("Hue: " + hue + ", Saturation:" + saturation
+ ", Brightness:" + brightness,10,50);
}
}
Example Output

Bookmark/Search this post with: