im4java转换使用管道

时间:2016-11-02 03:46:14

标签: java imagemagick imagemagick-convert im4java

我正在尝试处理管道的im4java示例TestCase10。

https://github.com/Widen/im4java/blob/master/src/org/im4java/test/TestCase10.java

 
public class im4Test {

    public static void main(String[] args) throws Exception {
        IMOperation op = new IMOperation();
        op.addImage("-");                   // read from stdin
        op.addImage("tif:-");               // write to stdout in tif-format

        // set up pipe(s): you can use one or two pipe objects
        FileInputStream fis = new FileInputStream("ABC.png");
        FileOutputStream fos = new FileOutputStream("ABC.tif");
        // Pipe pipe = new Pipe(fis,fos);
        Pipe pipeIn  = new Pipe(fis,null);
        Pipe pipeOut = new Pipe(null,fos);

        // set up command
        ConvertCmd convert = new ConvertCmd();
        convert.setInputProvider(pipeIn);
        convert.setOutputConsumer(pipeOut);
        convert.run(op);
        fis.close();
        fos.close();
    }
}

面对下面的例外情况,我们非常感谢任何有关发生事件的线索。



        Exception in thread "main" org.im4java.core.CommandException: java.io.IOException: The pipe is being closed
        at org.im4java.core.ImageCommand.run(ImageCommand.java:219)
        at com.cvc.image.im4Test.main(im4Test.java:28)
    Caused by: java.io.IOException: The pipe is being closed
        at java.io.FileOutputStream.writeBytes(Native Method)
        at java.io.FileOutputStream.write(FileOutputStream.java:326)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:122)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at java.io.FilterOutputStream.close(FilterOutputStream.java:158)
        at org.im4java.process.ProcessStarter.processInput(ProcessStarter.java:261)
        at org.im4java.process.ProcessStarter.waitForProcess(ProcessStarter.java:423)
        at org.im4java.process.ProcessStarter.run(ProcessStarter.java:313)
        at org.im4java.core.ImageCommand.run(ImageCommand.java:215)
        ... 1 more

 

注意:在Windows上运行,并使用ImageMagick。

1 个答案:

答案 0 :(得分:0)

发现问题,进一步调试。将其作为对他人利益的回答。

Windows平台有自己的'convert'命令,它正在干扰。

Ecplise IDE正在选择Windows命令,即使我确保ImageMagick'convert'命令位于系统路径中并可在命令行中访问并重新启动Eclipse。

要使其正常工作,必须明确设置ImageMagick搜索路径。

ConvertCmd.setSearchPath('imageMagickBinDirPath')