Java getSubimage() outside of raster

前端 未结 2 1252
陌清茗
陌清茗 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:22

    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

提交回复
热议问题