栅格格式异常

时间:2013-10-11 13:11:16

标签: java exception sprite

我一直在尝试为我们的游戏创建精灵,但问题是当我试图运行程序时出现此错误

Exception in thread "main" java.awt.image.RasterFormatException: (y + height) is outside of Raster
at sun.awt.image.ByteInterleavedRaster.createWritableChild(Unknown Source)
at java.awt.image.BufferedImage.getSubimage(Unknown Source)
at really.sprite.TrueSprite.<init>(TrueSprite.java:31)
at really.sprite.Sprite.main(Sprite.java:13)

这是导致错误的程序:

public class TrueSprite
{
BufferedImage spriteSheet = ImageIO.read(new File("resources/robin.png"));

int width = 240, height = 314, rows = 5 , columns = 5;

BufferedImage[] sprites = new BufferedImage[rows * columns];

public TrueSprite(int width, int height, int rows, int columns) throws IOException
{
this.width = width;
this.height = height;
this.rows = rows;
this.columns = columns;

for(int i = 0; i < rows; i++)
{
    for(int j = 0; j < columns; j++)
    {
        sprites[(i * columns) + j ] = spriteSheet.getSubimage(i * width, j * height, width, height);
    }
}

}

public void paint(Graphics g)
{
g.drawImage(sprites[1], 314, 240, null);
}


}

我导入的图像尺寸为1200 x 1570。

0 个答案:

没有答案