How to Convert Given HSB into RGB Parameters in Java


This exmaple would help us learn how to convert Hue, Saturation, and brightness model (HSB) to Red,Green, and Blue (RGB) model with AWT Color class in Java.

Source Code

package com.beginner.examples;

import java.awt.Color;

public class HSBToRGBExamples {

	public static void main(String[] args) {

		int rgb = Color.HSBtoRGB(0.3f, 0.03f, 0.5f);
		
		Color color = new Color(rgb);

		int r = color.getRed();
		int g = color.getGreen();
		int b = color.getBlue();

		System.out.println("rgb:" + rgb + "nr:" + r + "ng:" + g + "nb:" + b);

	}

}

Output:

rgb:-8617860
r:124
g:128
b:124

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments