im4java FileNotFoundException

时间:2015-02-13 16:39:12

标签: filenotfoundexception im4java

当我在eclipse中使用ImageMagick + im4java时,我总是有这个错误:

Exception in thread "main" org.im4java.core.CommandException: java.io.FileNotFoundException: convert
    at org.im4java.core.ImageCommand.run(ImageCommand.java:219)
    at imagetools.ImageTools.resizeImage(ImageTools.java:71)
    at imagetools.ImageTools.main(ImageTools.java:92)
Caused by: java.io.FileNotFoundException: convert
    at org.im4java.process.ProcessStarter.searchForCmd(ProcessStarter.java:661)
    at org.im4java.process.ProcessStarter.startProcess(ProcessStarter.java:403)
    at org.im4java.process.ProcessStarter.run(ProcessStarter.java:312)
    at org.im4java.core.ImageCommand.run(ImageCommand.java:215)

我确信ImageMagick本身在我的计算机上运行良好(Mac OSX 10.10.1)。 这是我的代码:

package imagetools;


import org.im4java.process.ProcessStarter;

import org.im4java.core.ConvertCmd;
import org.im4java.core.IMOperation;


public class ImageTools {       
public static void resizeImage(int width, int height, String srcPath, String newPath) throws Exception {
        IMOperation op = new IMOperation();
        op.addImage(srcPath);       
        op.resize(width, height);
        op.addImage(newPath);        
        ConvertCmd convert = new ConvertCmd();               
        convert.run(op);
    }   
public static void main(String[] args) throws Exception{
        String src =  "/Users/lvxinyun/Downloads/im4java-1.4.0/images.src/rose1.jpg"; 
        String n = "/Users/lvxinyun/Downloads/im4java-1.4.0/images.src/rose1_n.jpg";
        ProcessStarter.setGlobalSearchPath("/Users/lvxinyun/Downloads/ImageMagick-6.9.0-5");
        resizeImage(600,800,src,n);
    }
}

3 个答案:

答案 0 :(得分:2)

cd C:\Program Files\ImageMagick-7.0.5-Q16
copy magick.exe convert.exe

答案 1 :(得分:-1)

您必须安装IM4JAVA_TOOLPATH = "C:\Program Files\ImageMagick-6.9.1-Q16并设置# jobs/index.html.haml .panel .panel-heading %h4 Statistics .panel-body .col-md-9.col-xs-9 %h5.pull-left Users .col-md-3.col-xs-3 %h5.pull-right= @usercount .col-md-9.col-xs-9 %h5.pull-left Companies .col-md-3.col-xs-3 %h5.pull-right= @companycount .col-md-9.col-xs-9 %h5.pull-left Categories .col-md-3.col-xs-3 %h5.pull-right= @categorycount .col-md-9.col-xs-9 %h5.pull-left Total offers gathered .col-md-3.col-xs-3 %h5.pull-right= @jobcount (您的安装路径)

您可以在此处查看详情:http://im4java.sourceforge.net/docs/dev-guide.html

答案 2 :(得分:-1)

设置类路径很重要。 下载最新版本的ImageMagick和exiftool。 安装ImageMagick。 使用安装目录创建String var。

String myPath = "C:\\Program Files\\ImageMagick-7.0.8-Q16;C:\\Program Files\\exiftool-11.53";

按如下所述将其设置为OS命令:

ProcessStarter.setGlobalSearchPath(myPath);

Reference