首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >emf到jpg转换

emf到jpg转换
EN

Stack Overflow用户
提问于 2011-02-08 06:54:52
回答 4查看 5K关注 0票数 6

我的目标是将emf、wmf文件格式转换为其他图像文件格式。

我包括了image4java jar,并试图将我的emf文件转换成其他格式,如jpg、png。使用以下代码:

代码语言:javascript
复制
import org.im4java.core.ConvertCmd;
import org.im4java.core.IMOperation;
import java.io.File;
public class im4java {
    public static void main(String arg[])
    {
        File input=new File("src/image.emf");
        File output=new File("src/output.jpg");
        convertemf2png(input,output);
    }
    public static void convertemf2png(File input,File output)
    {
        try{
        IMOperation img=new IMOperation();
        img.addImage();
        img.addImage();
        ConvertCmd convert=new ConvertCmd();
        convert.run(img,new Object[]{input,output});
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

当我执行它时,我得到的错误如下

  1. 当我使用简单的convert.run(img,new Object[]{input,output});java.lang.IllegalArgumentException: java.io.File is an unsupported image-type 在org.im4java.core.ImageCommand.resolveImages(ImageCommand.java:289) at org.im4java.core.ImageCommand.prepareArguments(ImageCommand.java:189) at org.im4java.core.ImageCommand.run(ImageCommand.java:208) at im4java.convertemf2png(im4java.java:27) at im4java.main(im4java.java:18)

当我使用,`convert.run(img,新的Object[]{input.getAbsolutePath(),output.getAbsolutePath()});

代码语言:javascript
复制
 org.im4java.core.CommandException: org.im4java.core.CommandException: Invalid Parameter - C:\vignesh\im4java\src\output.jpg
        at org.im4java.core.ImageCommand.run(ImageCommand.java:215)
        at im4java.convertemf2png(im4java.java:27)
        at im4java.main(im4java.java:18)
Caused by: org.im4java.core.CommandException: Invalid Parameter - C:\vignesh\im4java\src\output.jpg
        at org.im4java.core.ImageCommand.finished(ImageCommand.java:247)
        at org.im4java.process.ProcessStarter.run(ProcessStarter.java:314)
        at org.im4java.core.ImageCommand.run(ImageCommand.java:211)

任何人请帮助我在此问题或任何其他方式转换emf格式的图像到其他formats..Thanks预先。

EN

回答 4

Stack Overflow用户

发布于 2011-06-03 21:04:36

您需要设置ImageMagic可执行文件的路径??您无意中调用了一个名为convert的windows程序

票数 4
EN

Stack Overflow用户

发布于 2012-04-23 10:16:16

还需要在使用im4java命令之前添加这些行:

代码语言:javascript
复制
String myPath="PATH\TO\ImageMagick";
ProcessStarter.setGlobalSearchPath(myPath);
票数 3
EN

Stack Overflow用户

发布于 2015-09-27 18:32:27

把你的图像放在字符串中。确保将环境变量IM4JAVA_TOOLPATH设置为imagemagick路径。

代码语言:javascript
复制
import org.im4java.core.ConvertCmd;
import org.im4java.core.IMOperation;

public class im4java {
    public static void main(String arg[])
    {
        String input = "src/image.emf";
        String output = "src/output.jpg";
        convertemf2png(input,output);
    }
    public static void convertemf2png(String input,String output)
    {
        try{
        IMOperation img=new IMOperation();
        img.addImage();
        img.addImage();
        ConvertCmd convert=new ConvertCmd();
        convert.run(img,input,output);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4930387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档