Java 光栅格式异常
我一直在尝试为我们的游戏创建一个精灵,但问题是当我试图运行程序时,出现了这个错误Java 光栅格式异常,java,exception,sprite,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.get
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)
线程“main”java.awt.image.RasterFormatException中的异常:(y+高度)在光栅之外
位于sun.awt.image.ByteInterleavedRaster.createWritableChild(未知源)
位于java.awt.image.BuffereImage.getSubimage(未知源)
在really.sprite.TrueSprite。(TrueSprite.java:31)
位于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);
}
}
公共类TrueSprite
{
buffereImage spriteSheet=ImageIO.read(新文件(“resources/robin.png”);
整数宽度=240,高度=314,行=5,列=5;
BuffereImage[]精灵=新的BuffereImage[行*列];
公共TrueSprite(整数宽度、整数高度、整数行、整数列)引发IOException
{
这个。宽度=宽度;
高度=高度;
this.rows=行;
this.columns=列;
对于(int i=0;i
我导入的图像大小是1200 x 1570。什么是
spriteSheet.getWidth
和spriteSheet.getHeight
打印?高度是1570,宽度是1200