简体   繁体   English

使用Java运行image magic的convert命令导致无法加载模块错误

[英]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.

相关问题 在命令行上运行模块会出现错误:找不到模块目标 - Running a module on command line gives error : Module target not found 通过Java命令使用image magick转换图像时提示错误 - Convert image using image magick via java command says error Sqldeveloper在Fedora上使用Java运行时给出错误 - Sqldeveloper gives error on running using java on Fedora Java在命令提示符下出现错误的幻数错误 - Bad Magic Number Error In Java At Command Prompt Vim:从vim命令运行java会出错 - Vim: running java from vim command gives error Java Swing:无法使用getResource加载图像 - Java Swing: unable to load image using getResource 我在 Mac 中使用 java 运行 curl 命令时遇到以下错误,它给出 IOException 并说无法运行程序 - I am having below error while running curl command using java in Mac where it gives IOException and says cannot run the program 使用eclipse,java maven项目可以编译,但是在运行时会给出错误 - using eclipse, java maven project compiles but gives error when running Google Dataflow作业在Eclipse上运行时工作正常,但是当我使用mvn进行编译并使用java -cp命令运行文件时出现错误 - Google Dataflow job working fine when running on eclipse but gives an error when i compile it using mvn and run the file using java -cp command AWS Polly Java客户端提供错误:无法从链中的任何提供程序加载区域信息 - AWS Polly Java Client gives error: Unable to load region information from any provider in the chain
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM