我一直在尝试从许多 BufferedImage 格式的较小图像中绘制一个巨大的图像文件(使用一个大的 BufferedImage 占用的内存比我所拥有的更多),现在我试图通过 ImageWriter 类的 replacePixels-Function 来做到这一点。
然而; 我确实遇到了一个令人费解的错误,即使是广泛的谷歌搜索也无法解决,所以我希望这里有人能告诉我我做错了什么:
javax.imageio.IIOException: Illegal byte order
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.locateIFD(TIFFImageWriter.java:2813)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.readIFD(TIFFImageWriter.java:3076)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.canReplacePixels(TIFFImageWriter.java:3099)
at drawingTiles.WorldMapMaker$1.writeImg(WorldMapMaker.java:90)
at drawingTiles.WorldMapMaker$1.run(WorldMapMaker.java:148)
at java.lang.Thread.run(Unknown Source)
javax.imageio.IIOException: Illegal byte order
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.locateIFD(TIFFImageWriter.java:2813)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.readIFD(TIFFImageWriter.java:3076)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter.prepareReplacePixels(TIFFImageWriter.java:3141)
at drawingTiles.WorldMapMaker$1.writeImg(WorldMapMaker.java:104)
at drawingTiles.WorldMapMaker$1.run(WorldMapMaker.java:148)
at java.lang.Thread.run(Unknown Source)
我确实知道字节顺序是什么,但我不知道字节顺序怎么会是非法的。这是我正在使用的功能:
public void writeImg (String path, int startx, int starty, BufferedImage image){
File output = new File(path);
ImageOutputStream ios = null;
try {
ios = ImageIO.createImageOutputStream(output);
} catch (IOException e){
e.printStackTrace();
}
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("TIF");
ImageWriter writer = (ImageWriter)iter.next();
writer.setOutput(ios);
TIFFImageWriteParam writeParam = new TIFFImageWriteParam(Locale.ENGLISH);
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
try{
if(writer.canReplacePixels(0)){ // LINE 90
System.out.println("True");
}else{
System.out.println("False");
}
}catch (IOException e) {
e.printStackTrace();
}
Point destinationOffset = new Point(startx,starty);
writeParam.setDestinationOffset(destinationOffset);
try {
writer.prepareReplacePixels(0, new Rectangle(0, 0, image.getWidth(), image.getHeight())); // LINE 104
writer.replacePixels(image, writeParam);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}