Getting pixel data from an image using java

前端 未结 6 1147
眼角桃花
眼角桃花 2020-12-02 14:11

I\'m trying to get the pixel rgb values from a 64 x 48 bit image. I get some values but nowhere near the 3072 (= 64 x 48) values that I\'m expectin

6条回答
  •  旧时难觅i
    2020-12-02 14:23

    This:

    for(int i = 0; i < img.getHeight(); i++){
        for(int j = 0; j < img.getWidth(); j++){
            rgb = getPixelData(img, i, j);
    

    Does not match up with this:

    private static int[] getPixelData(BufferedImage img, int x, int y) {
    

    You have i counting the rows and j the columns, i.e. i contains y values and j contains x values. That's backwards.

提交回复
热议问题