具体来说,我正在尝试在Java上运行下一行:

 convert /home/mohamed.hegab/Desktop/1263392123111.jpg -gamma .45455 -resize 400x400 -gamma 2.2 -quality 92 /home/mohamed.hegab/Desktop/small.jpg


在bash命令行上运行得很好
但是当我使用进程生成器在Java上运行它时,它给了我奇怪的结果。

public static void resizeImage(String srcPath, String destPath,String size) {

        ProcessBuilder pb = new ProcessBuilder("convert", srcPath , " -gamma", ".45455",
                " -resize",size, " -gamma ", "2.2", " -quality",
                "92" , destPath);
        pb.redirectErrorStream(true);
        InputStreamReader isr = null;
        BufferedReader br = null;
        try {
            Process p = pb.start();
            p.waitFor();
            isr = new InputStreamReader(p.getInputStream());
            br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (Exception e) {
            LOG.error("Exception while trying to convert text to image", e);
        } finally {
            try {
                if(isr != null) {
                    isr.close();
                }
                if(br != null) {
                    br.close();
                }
            } catch (IOException e) {
                LOG.error("Could not close stream", e);
            }
        }
    }


system.out中出现的行很奇怪,很奇怪,它说



转换:无法打开图像-gamma': No such file or directory @ blob.c/OpenBlob/2439.convert: unable to open image .45455':没有这样的文件或目录@ blob.c / OpenBlob / 2439。
转换:无法打开图像-resize': No such file or directory @ blob.c/OpenBlob/2439.convert: unable to open image 400x400':无此类文件或目录@ blob.c / OpenBlob / 2439。
转换:无法打开图像-gamma ': No such file or directory @ blob.c/OpenBlob/2439.convert: unable to open image 2.2':没有此类文件或目录@ blob.c / OpenBlob / 2439。
转换:无法打开图像-quality': No such file or directory @ blob.c/OpenBlob/2439.convert: unable to open image 92':没有这样的文件或目录@ blob.c / OpenBlob / 2439。



但是图像仅以960 * 960的尺寸显示,我不知道它来自哪里。

所以任何人都可以在这方面帮助我:)

最佳答案

-之前避免空格,shell命令只能识别以-开头的选项。

07-26 06:35