图像IO无法写入 JPEG 文件
2022-08-31 16:24:04
我有一个缓冲图像,我试图写入jpeg文件,但我的Java程序抛出了一个异常。我能够成功地将相同的缓冲区保存到gif和png。我尝试过在Google上寻找解决方案,但无济于事。
法典:
File outputfile = new File("tiles/" + row + ":" + col + ".jpg");
try {
ImageIO.write(mapBufferTiles[row][col], "jpg", outputfile);
} catch (IOException e) {
outputfile.delete();
throw new RuntimeException(e);
}
例外:
Exception in thread "main" java.lang.RuntimeException: javax.imageio.IIOException: Invalid argument to native writeImage
at MapServer.initMapBuffer(MapServer.java:90)
at MapServer.<init>(MapServer.java:24)
at MapServer.main(MapServer.java:118)
Caused by: javax.imageio.IIOException: Invalid argument to native writeImage
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeOnThread(JPEGImageWriter.java:1055)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:357)
at javax.imageio.ImageWriter.write(ImageWriter.java:615)
at javax.imageio.ImageIO.doWrite(ImageIO.java:1602)
at javax.imageio.ImageIO.write(ImageIO.java:1526)
at MapServer.initMapBuffer(MapServer.java:87)
... 2 more