Java BufferedImage to RGB getRgbFromImage(BufferedImage image)

Here you can find the source of getRgbFromImage(BufferedImage image)

Description

Get RGB data array from given image

License

Open Source License

Parameter

Parameter Description
image Image

Return

List with three elements of two-dimensional int's - R, G and B

Declaration

public static List<int[][]> getRgbFromImage(BufferedImage image) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*  w w w  . j  ava 2s.co m*/
     * Get RGB data array from given image
     * 
     * @param image Image
     * @return List with three elements of two-dimensional int's - R, G and B
     */
    public static List<int[][]> getRgbFromImage(BufferedImage image) {
        List<int[][]> rgb = new ArrayList<int[][]>();
        int[][] r = null;
        int[][] g = null;
        int[][] b = null;
        int width = 0;
        int height = 0;

        width = image.getWidth();
        height = image.getHeight();

        r = new int[height][width];
        g = new int[height][width];
        b = new int[height][width];

        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                r[i][j] = (image.getRGB(j, i) >> 16) & 0xFF;
                g[i][j] = (image.getRGB(j, i) >> 8) & 0xFF;
                b[i][j] = (image.getRGB(j, i) >> 0) & 0xFF;
            }
        }

        rgb.add(r);
        rgb.add(g);
        rgb.add(b);

        return rgb;
    }
}

Related

  1. getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels)
  2. getRGB(BufferedImage img)
  3. getRGBPixels(BufferedImage img)
  4. imageToMatrix(BufferedImage image)
  5. imageToPixels(BufferedImage image)
  6. imageToRGBABuffer(BufferedImage img)