How to Convert HSB to RGB in Java


In this example, we’ll learn how to convert Red,Green, and Blue (RGB) to Hue, Saturation, and brightness model (HSB) with java AWT Color class.

Source Code

package com.beginner.examples;

import java.awt.Color;
import java.util.Arrays;

public class ConvertRGBToHSBExample {

	public static void main(String[] args) {

		float[] hsb = new float[3];

		//Pass in the RGB parameter
		//If the fourth argument is Null, an array of float types is returned
		Color.RGBtoHSB(255, 100, 60, hsb);

		System.out.println("HSB:" + Arrays.toString(hsb));

	}

}

Output:

HSB:[0.034188032, 0.7647059, 1.0]

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments