我想将像素返回给调用函数,但只有最后一个值是 getin,这意味着它会覆盖该值...
get_pixel_info() 方法正在调用 getPixelData(),在 getPixelData() 方法中,第一个像素 rgb 的值存储在 rgb[] 数组中并返回 rgb 返回到调用函数,因为 for 循环再次控制敌人到 getPixelData() 方法和这个时间覆盖第一个像素上的第二个像素的值,依此类推..我想要所有像素的所有值,但只得到 1
像素 rgb 的值应该返回给调用函数请帮助
public static int[] get_pixel_info() 
{
    int[] rgb={0};
    int[][] rgb2 = new int[0][0];
    BufferedImage img;
    try 
    {
        img = ImageIO.read(new File(IMG));
        int[][] pixelData = new int[img.getHeight() * img.getWidth()][3];
        int counter = 0;
        for(int i = 0; i < img.getWidth(); i++) 
        {
            for(int j = 0; j < img.getHeight(); j++) 
            {
                rgb = getPixelData(img, i, j);
                for(int k = 0; k < rgb.length; k++) 
                {
                    pixelData[counter][k] = rgb[k];
                }
                counter++;                
            }            
        }
    } 
   catch (IOException e) 
   {
        e.printStackTrace();
   }
    return rgb;
}
public static int[] getPixelData(BufferedImage img, int x, int y) 
 {
    int argb = img.getRGB(x, y);   
    int rgb[] = new int[] {            
        ((argb >> 16) & 0xff), //red             
        (argb >> 8) & 0xff, //green
        (argb ) & 0xff //blue
    };
    System.out.println("rgb: " + Integer.toBinaryString(rgb[0]) + " " +        Integer.toBinaryString(rgb[1]) + " " + Integer.toBinaryString(rgb[2]));
    return rgb;
}