Get Red, Green, and Blue (RGB) Components From Color - Java 2D Graphics

Java examples for 2D Graphics:Color RGB

Description

Get Red, Green, and Blue (RGB) Components From Color

Demo Code

 
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
 
public class Main {
       //from w  w  w. j a v  a2  s .co m
        public void paint(Graphics g){
                //create a custom color using HSB
                Color customColor = Color.getHSBColor(0.9f,0.5f,0.8f);
                int red, green, blue;
                red = customColor.getRed();
                green = customColor.getGreen();
                blue = customColor.getBlue();
               
                g.drawString("Red:" + red +", Green:" + green + ", blue:" + blue, 10,50);
               
        }
}

Related Tutorials