Java getSubimage() outside of raster

时光毁灭记忆、已成空白 提交于 2019-11-28 14:03:17

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);

From the javadoc

* @param x the X coordinate of the upper-left corner of the
*          specified rectangular region
* @param y the Y coordinate of the upper-left corner of the
*          specified rectangular region
* @param w the width of the specified rectangular region
* @param h the height of the specified rectangular region

this means the following line is wrong

image.getSubimage(x,y,x + width,y + height);

it should be something like

image.getSubimage(x, y, width, height);

For a full working example take a look at this paste

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!