Search code examples
javabufferedimage

Java BufferedImage getting red, green and blue individually


The getRGB() method returns a single int. How can I get individually the red, green and blue colors all as the values between 0 and 255?


Solution

  • Java's Color class can do the conversion:

    Color c = new Color(image.getRGB());
    int red = c.getRed();
    int green = c.getGreen();
    int blue = c.getBlue();