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