How to Get RGB Value For Current Color in Java


This example will tell us how to get Red, Green, and Blue (RGB) value from color with AWT Color class in JavaJava .

Source Code

package com.beginner.examples;

import java.awt.Color;

public class GetRGBValueExample {

	public static void main(String[] args) {

		Color custom = new Color(0.3f, 0.02f, 0.2f);

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

		System.out.println("R:" + r + "nG:" + g + "nB:" + b);

	}

}

Output:

R:77
G:5
B:51

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments