[英]Running convert command of image magic using Java gives unable to load module error
I have written a class that execute convert command of imagemagic. 我写了一个执行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();
}
}
}
But I am getting the following response 但我得到以下回应
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.
Same problem is with .png file.I have installed ImageMagick-6.9.1-2-Q16-x64-dll.exe on Window8. .png文件也存在同样的问题。我已经在Window8上安装了ImageMagick-6.9.1-2-Q16-x64-dll.exe。 However if I run the following command on command prompt
但是,如果我在命令提示符下运行以下命令
convert -resize 1024x768 G:\\demo\\image\\frame.jpg G:\\demo\\image\\resizeImage\\frame1.jpg
It successfully execute and copy the resized image in destination folder.If anyone knows please reply. 它成功执行并复制了调整大小后的图像到目标文件夹中。如果有人知道,请回复。
Thanks 谢谢
I can get it to work, only if I change the working directory from which the executed is to be run, using ProcessBuilder#directory(File)
只有使用
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();
}
In my case it allready helped to install the static Version of ImageMagick instead off the dynamic/dll . 就我而言,它已经准备好帮助安装ImageMagick的静态版本,而不是从dynamic / dll安装 。 Give it a try.
试试看。 Btw.
顺便说一句。 call-funktionality should be same with x86 or x64.
呼叫功能应该与x86或x64相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.