Convert emf to jpg

My goal is to convert emf, wmf file formats to other image file formats.

I included java image4java and tried to convert my emf file to other formats like jpg, png .. using the following code:

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();
        }
    }
}

while i execute it i got an error like

  • when i just use convert.run(img,new Object[]{input,output});i got

    java.lang.IllegalArgumentException: java.io.File is an unsupported image-type

            at 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)
    

when I use `convert.run (img, new Object [] {input.getAbsolutePath (), output.getAbsolutePath ()}); I got,

 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)

someone please help me in solving this problem or any other way to convert emf formatt image to other formats. Thanks in advance.

+5
source share
3 answers

ImageMagic - Windows convert

+4

im4java:

String myPath="PATH\TO\ImageMagick";
ProcessStarter.setGlobalSearchPath(myPath);
+3

Put the images in rows. Make sure you set the IM4JAVA_TOOLPATH environment variable to your imagemagick path.

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();
        }
    }
}
0
source

All Articles