我编写了一个执行imagemagic转换命令的类。
public class ImageMagicDemo {
public static void main(String[] argp){
ProcessBuilder pb2 = new ProcessBuilder("G:\\project\\installation\\imagemagic\\convert","G:\\demo\\image\\frame.jpg", "-resize", "20x20",
"G:\\demo\\image\\resizeImage\\frame1.jpg");
pb2.redirectErrorStream(true);
Process p2;
try {
p2 = pb2.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p2.getInputStream()));
String line = null;
while((line=br.readLine())!=null){
System.out.println(line);
}
System.out.println("2"+p2.waitFor());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
但我得到以下回复
convert.exe: unable to open image `G:\demo\image\frame.jpg': No such file or directory @ error/blob.c/OpenBlob/2692.
convert.exe: unable to load module `G:\project\installation\imagemagic\modules\coders\IM_MOD_RL_JPEG_.dll': The specified module could not be found.
@ error/module.c/OpenModule/1282.
convert.exe: no decode delegate for this image format `JPG' @ error/constitute.c/ReadImage/501.
convert.exe: no images defined `G:\demo\image\resizeImage\frame1.jpg' @ error/convert.c/ConvertImageCommand/3212.
同样的问题是.png文件。我在Window8上安装了ImageMagick-6.9.1-2-Q16-x64-dll.exe。 但是,如果我在命令提示符下运行以下命令
convert -resize 1024x768 G:\\demo\\image\\frame.jpg G:\\demo\\image\\resizeImage\\frame1.jpg
它成功执行并复制了目标文件夹中已调整大小的图像。如果有人知道请回复。
谢谢
答案 0 :(得分:5)
只有当我使用ProcessBuilder#directory(File)
ProcessBuilder pb = new ProcessBuilder(
"C:\\Program Files\\ImageMagick-6.9.1-Q16\\convert.exe",
"C:\\Path\to\Large.png",
"-resize", "1027x768",
"C:\\Path\to\small.png");
try {
pb.inheritIO();
pb.redirectErrorStream();
pb.directory(new File("C:\\Program Files\\ImageMagick-6.9.1-Q16"));
Process p = pb.start();
try (InputStream is = p.getInputStream()) {
int in = -1;
while ((in = is.read()) != -1) {
System.out.print((char)in);
}
}
System.out.println("Exited with " + p.waitFor());
} catch (IOException | InterruptedException ex) {
ex.printStackTrace();
}
答案 1 :(得分:0)
在我的情况下,它已经帮助安装静态版本的ImageMagick而不是 dynamic / dll 。试试看。顺便说一句。 call-funktionality应与x86或x64相同。