2

对于我的一个项目,我正在使用 im4java 库并通过它向 graphicsmagick 发送命令。

获取图像大小:

identify -format \"%w,%h,\"  test.png

我可以正确获得尺寸,直到以下结果。这次 stderr 改变了结果:

[wx=0.345750,  wy=0.358550,  rx=0.648500,  ry=0.330880
gx=0.321210,  gy=0.597870,  bx=0.155890,  by=0.066040
163, 70, 
identify: Ignoring incorrect cHRM value when sRGB is also present ]

有什么方法可以获取图像大小并忽略 stderr 结果?

提前致谢

4

3 回答 3

0

尝试添加-quiet到您的命令以抑制错误消息,如下所示:

identify -quiet -format \"%w,%h,\"  test.png
于 2015-07-02T11:26:43.730 回答
0

// 对我来说,“ping”是获取维度的最快方法。

        String resultFormat = "%w" + " " + "%h";
        ArrayListOutputConsumer outputConsumer = new ArrayListOutputConsumer();

        IdentifyCmd identify = new IdentifyCmd();

        identify.setOutputConsumer(outputConsumer);
        IMOperation op = new IMOperation();
        op.ping();
        op.format(resultFormat);
        op.addImage("abc.jpg");

        //Object[] arguments = new String[]{filePath};

        try {
                identify.createScript("c:\\_work\\temp\\magick-dimension.sh.txt", op);  // this will show you the actual im4java generated command
                identify.run(op);

        } catch (IOException | InterruptedException | IM4JavaException e) {
                //throw new ImageAccessException(e.getMessage(), e);
                e.printStackTrace();
        }

        ArrayList<String> output = outputConsumer.getOutput();

        String[] dimensions = output.get(0).split(separator);
        Dimension result = new Dimension(Integer.valueOf(dimensions[0]), Integer.valueOf(dimensions[1]));
        return result;
于 2017-11-03T12:39:44.683 回答
0

请执行下列操作:

识别 -format \"width=%w,height=%h,\" test.png

然后解析结果专门寻找width=N和height=N

于 2017-01-31T10:41:42.927 回答