gpt4 book ai didi

java - 为 createWritableChild 切割图像 IllegalArgumentException

转载 作者:行者123 更新时间:2023-11-30 09:50:39 26 4
gpt4 key购买 nike

所以我希望有人能够帮助我解决这个问题。我正在为我的计算机图形学类(class)编写一个拼图游戏,在尝试将我的图像切成碎片时遇到了一些障碍。我相信问题出在 createWritableChild 上,但老实说,这个错误消息并不十分清楚,所以我不确定。这是我的错误:

线程“AWT-EventQueue-0”中的异常 java.lang.IllegalArgumentException: Raster ByteInterleavedRaster: width = 45 height = 45 #numDataElements 3 dataOff[0] = 137 的 minX 或 minY 不等于零:45 0 在 java.awt.image.BufferedImage.(未知来源) 在 JigsawPuzzle.runPuzzleCreate(JigsawPuzzle.java:106) 在 JigsawPuzzle.gameBoardCreate(JigsawPuzzle.java:137) 在 JigsawPuzzle$3.paintComponent(JigsawPuzzle.java:65)

这是我抛出错误的代码:

//Cuts up the given Image and creates the Puzzle and its Pieces.
public Puzzle runPuzzleCreate(BufferedImage p){
int pieceCount = 150;
int pieceSize = 45;
Piece[] pieces = new Piece[pieceCount];
Piece[] scaled = new Piece[pieceCount];
Puzzle puzzle = new Puzzle(p, pieces, scaled);
ColorModel cm = p.getColorModel();
boolean premult = cm.isAlphaPremultiplied();
WritableRaster raster = p.copyData(null);
Posn pos = new Posn(0, 0);
for(int i = 0; i < pieceCount; i++){
if(pos.xPos <= 555){
WritableRaster childRaster =
raster.createWritableChild(pos.xPos, pos.yPos,
pieceSize, pieceSize,
pos.xPos, pos.yPos,
null);
BufferedImage pieceImage = new BufferedImage(cm, childRaster,
premult, null);
Piece piece = new Piece(pieceImage, pos);
pieces[i] = piece;
scaled[i] = piece;
pos.xPos += pieceSize;
} else if (pos.yPos <= 450){
pos.yPos += pieceSize;
pos.xPos = 0;
} else {
break;
}
}
return puzzle;
}

最佳答案

很遗憾没有记录这个异常,但是查看它的消息和 BufferedImage 的源代码,似乎您需要为 raster.createWritableChild( ) 方法调用。

关于java - 为 createWritableChild 切割图像 IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5069678/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com