小编Emi*_*ily的帖子

栅格之外的Java getSubimage()

我正在尝试拍摄图像并将其存储在16x16子图像的数组中.我使用的图像是512x512像素.但是,在遍历循环时,getSubimage()会被Raster异常停止.

这是代码:

public class TileList extends JPanel {

  private static final int width = 16;          //width of a tile
  private static final int height = width;
  private int col = 1;
  private int row = 1;

  private BufferedImage image;
  File tilesetImage = new File("image.png");
  BufferedImage tileset[];

  public void loadAndSplitImage (File loadImage) {
    try{
        image = ImageIO.read(loadImage);
    }catch(Exception error) {
        System.out.println("Error: cannot read tileset image.");
    }// end try/catch
    col = image.getWidth()/width;
    row = image.getHeight()/height;
    tileset = new BufferedImage[col*row];
  }// end loadAndSplitImage …
Run Code Online (Sandbox Code Playgroud)

java bufferedimage raster

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

bufferedimage ×1

java ×1

raster ×1