Getting pixel data from an image using java

前端 未结 6 1146
眼角桃花
眼角桃花 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:35

    You have to change:

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

    Into

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

    Because the second parameter from getPixelData is the x-value and the thirth is the y-value. You switched the parameters.

提交回复
热议问题