raster.setPixels(0,0,h,w,pixtotal);
Per the Oracle documentation, setPixels
takes the parameters x, y, w, h, iArray
. You've swapped width and height, which would logically swap the dimensions of the image. This also dramatically changes how the pixels in the array are parsed, without causing any errors.
The same problem applies to your new BufferedImage(h,w, BufferedImage.TYPE_BYTE_GRAY)
.
Finally, I don't see where i
is defined, but "increment by 1" is not generally how pixels are indexed into a 1-dimensional array. x + (y * w)
should be the correct index for any given pixel.