RegisterForgot Your Password?

HSB to RGB Color

Convert HSB To RGB Color Example.This java example shows how to convert Hue, Saturation, and brightness model (HSB) to Red,Green, and Blue (RGB) model using Java AWT Color class.

public class Color
extends Object
implements Paint, Serializable

The Color class is used encapsulate colors in the default sRGB color space or colors in arbitrary color spaces identified by a ColorSpace. Every color has an implicit alpha value of 1.0 or an explicit one provided in the constructor. The alpha value defines the transparency of a color and can be represented by a float value in the range 0.0 - 1.0 or 0 - 255. An alpha value of 1.0 or 255 means that the color is completely opaque and an alpha value of 0 or 0.0 means that the color is completely transparent. When constructing a Color with an explicit alpha or getting the color/alpha components of a Color, the color components are never premultiplied by the alpha component.

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

<applet code=”ConvertHSBToRGBColor” width=200 height=100>

public class ConvertHSBToRGBColor extends Applet{

public void paint(Graphics g){

* To convert HSB to RGB, use
* static int HSBtoRGB(float hue, float saturation, float brightness)
* method of AWT Color class.
* This method returns RGB equivalent set of values.

int rgb = Color.HSBtoRGB(0.6f,0.5f,0.8f);

//create new color from the RGB value
Color color = new Color(rgb);

//set foreground color of this applet

g.drawString(“Color converted from HSB to RGB”,10,50);