我正在尝试使用 im4java 将输入流中的图像转换为输出流。从文档中,它看起来像将 inputProvider 设置为输入并指定输出流应该管道转换后的图像,但我得到:
Failed to convert image: more argument images then placeholders
这是我的功能:
public static InputStream convert(InputStream imageStream){
try {
// Set up the im4java properties. See {@link im4java}
IMOperation op = new IMOperation();
op.scale(1000);
op.compress("Zip");
ConvertCmd convert = new ConvertCmd();
convert.setSearchPath(imLocation);
logger.debug("Imagemagick located at: " + convert.getSearchPath());
InputStream is = imageStream;
ByteArrayOutputStream os = new ByteArrayOutputStream();
Pipe pipeIn = new Pipe (is, null);
Pipe pipeOut = new Pipe(null, os);
convert.setInputProvider(pipeIn);
convert.setOutputConsumer(pipeOut);
convert.run(op, "-", "pdf:-");
is.close();
os.close();
pipeOut.consumeOutput(is);
return is;
}catch(Exception e){
logger.debug("Failed to convert image: " + e.getMessage());
}
return null;
}
谢谢!