【发布时间】:2019-08-21 11:28:02
【问题描述】:
我正在使用 im4java 来转换图像。以下程序因堆栈跟踪而崩溃:Caused by: org.im4java.core.CommandException: convert: insufficient image data in file /tmp/magick-254901G7YJ9qaMQv5' @ error/jpeg.c/ReadJPEGImage/1154.
看起来它正在生成一个临时文件。直接在 ImageMagick 命令行上运行相同的命令可以得到正确的结果。
我正在运行 ImageMagick-6.9.10-61 和 im4java 1.4.0
我想知道是否有人有任何见解。
IMOperation op = new IMOperation();
op.addImage("-");
op.addImage("jpg:-");
op.quality(0.85);
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// image is of type MultipartFile
Pipe pipeIn = new Pipe(image.getInputStream(), null);
Pipe pipeOut = new Pipe(null, outputStream);
convertCmd.setInputProvider(pipeIn);
convertCmd.setOutputConsumer(pipeOut);
convertCmd.run(op);
return outputStream.toByteArray();
} catch (Exception e) {
//
}
【问题讨论】:
-
您是否尝试过自己创建临时文件?只是为了检查它是管道还是其他东西。
-
@Thomas 我该怎么做?每次创建的临时文件都不一样。我可以配置要使用的文件吗?
标签: java imagemagick