我需要在我的 java 项目中使用 ImageMagic。我已经在 Windows 10 上安装了 ImageMagic-7.0.3(命令行工作正常)
然后,我在 maven 文件中添加了对 im4java 的依赖项。当我尝试执行以下操作时:
public static void main(String[] args) {
String imPath="C:\\Program Files\\ImageMagick-7.0.3-Q16";
ConvertCmd cmd = new ConvertCmd();
cmd.setSearchPath(imPath);
IMOperation op = new IMOperation();
op.addImage("biuro.jpg");
op.negate();
op.addImage("biuro_new.jpg");
try {
cmd.run(op);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IM4JavaException e) {
e.printStackTrace();
}
System.out.println("works");
}
我收到以下错误
org.im4java.core.CommandException: java.io.FileNotFoundException: convert
at org.im4java.core.ImageCommand.run(ImageCommand.java:219)
at Main.main(Main.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.io.FileNotFoundException: convert
at org.im4java.process.ProcessStarter.searchForCmd(ProcessStarter.java:661)
at org.im4java.process.ProcessStarter.startProcess(ProcessStarter.java:399)
at org.im4java.process.ProcessStarter.run(ProcessStarter.java:312)
at org.im4java.core.ImageCommand.run(ImageCommand.java:215)
... 6 more