emf to jpg conversion
My objective is to convert emf,wmf file formats to other image file formats.
I included image4java jar 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 the error like
when i use simply
convert.run(img,new Object[]{input,output});
i gotjava.lang.IllegalArgumentException: java.io.File is an unsupported image-type
开发者_StackOverflowat 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)
anyone please help me in fizing this issue or any other way to convert emf formatt image to other formats..Thanks in advance.
You need to set the path to the ImageMagic executable - you are inadvertently calling a windows program named convert
You also need to add these lines before using the im4java commands:
String myPath="PATH\TO\ImageMagick";
ProcessStarter.setGlobalSearchPath(myPath);
Put your images in Strings. Make sure you set the environment variable IM4JAVA_TOOLPATH 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();
}
}
}
I wrote a walkaround here, for Java I learned that I can run shell command this way. For jpg, try this:
libreoffice --headless --convert-to jpg /mnt/b.emf
精彩评论