Java getSubimage() outside of raster

前端 未结 2 1259
陌清茗
陌清茗 2020-12-11 18:41

I\'m trying to take an image and store it in an array of 16x16 subimages. The image I am using is 512x512 pixels. However, while iterating through the loop, getSubimage() is

2条回答
  •  长情又很酷
    2020-12-11 19:23

    You're passing the wrong parameters to getSubimage. The docs say...

    Parameters:
    x - the X coordinate of the upper-left corner of the specified rectangular region
    y - the Y coordinate of the upper-left corner of the specified rectangular region
    w - the width of the specified rectangular region
    h - the height of the specified rectangular region

    You're passing in x, y, x + width, y + width, which would mean if x = 256, width actually equals 256 + 16 = 272.

    So you new image would be ... x + width = 256 + 272 = 528, which is wider then your image area.

    You should be passing x, y, width, heigh

    tileset[q] = image.getSubimage(x, y, width, height);
    

提交回复
热议问题