width = 25;
height = 25;
h1Walking = new BufferedImage[6];
BufferedImage sprite1 = ImageIO.read(new File(getClass().getResource("/Resources/kirbywalk.gif").toURI()));
for(int i = 0; i < h1Walking.length; i++){
h1Walking[i] = sprite1.getSubimage(
i * width + i,
0,
width,
height
);
}
上面放置的代碼是在我的程序中返回錯誤的部分。我不明白爲什麼它這樣做有沒有人有任何想法,爲什麼它返回下面的錯誤?柵格格式異常(Y +高度)
java.awt.image.RasterFormatException: (y + height) is outside of Raster
at sun.awt.image.BytePackedRaster.createWritableChild(BytePackedRaster.java:1312)
at java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1196)
at Main.Horses.<init>(Horses.java:72)
at Main.HorseRacingGame.run(HorseRacingGame.java:113)
at java.lang.Thread.run(Thread.java:695)
嗨盧克,很好發現。並感謝您指出我自己的答案白癡......乾杯:-) –