ImageMagick转换在命令行中,但在Java Process运行时不工作
我有一个 tif 图像,我试图在其中绘制一个框并同时使用 LZW 压缩来压缩图像。
这是我正在运行的命令,它在 Windows 命令行中运行良好。
C:\ImageMagick-7.1.0\convert.exe "C:\Users\admin\Orig.tif" -draw "rectangle 576,1069,943,1114" -compress LZW "C:\Users\admin\DrawLZW.tif"
当我尝试使用 java 程序执行相同的命令时,我创建了一个图像文件,但文件大小为 1kb
String[] cmd = {"C:\\ImageMagick-7.1.0\\convert.exe", "\"C:\\Users\\chris.macwilliams\\Orig.tif\"", "-draw", "\"rectangle 576,1069,943,1114\"", "–compress","LZW", "\"C:\\Users\\chris.macwilliams\\DrawLZWwithJava.tif\""};
LOGGER.info(cmd);
Process pt = Runtime.getRuntime().exec(cmd);
pt.waitFor();
if (pt.exitValue() != 0) {
LOGGER.error("ERROR with Image Magic Command exit value:" + pt.exitValue()+ " "+ commandTIF);
这里有什么想法吗?
使用IM版本:ImageMagick-7.1.0 我已经包含了出现错误的测试图像。 zip 文件下载
I have a tif image where I am trying to draw a box and compress the image with LZW compression simultaneously.
this is the command I am running, and it works fine from windows command line.
C:\ImageMagick-7.1.0\convert.exe "C:\Users\admin\Orig.tif" -draw "rectangle 576,1069,943,1114" -compress LZW "C:\Users\admin\DrawLZW.tif"
when I try to execute the same command with my java program, I get an image file created, but the file size is 1kb
String[] cmd = {"C:\\ImageMagick-7.1.0\\convert.exe", "\"C:\\Users\\chris.macwilliams\\Orig.tif\"", "-draw", "\"rectangle 576,1069,943,1114\"", "–compress","LZW", "\"C:\\Users\\chris.macwilliams\\DrawLZWwithJava.tif\""};
LOGGER.info(cmd);
Process pt = Runtime.getRuntime().exec(cmd);
pt.waitFor();
if (pt.exitValue() != 0) {
LOGGER.error("ERROR with Image Magic Command exit value:" + pt.exitValue()+ " "+ commandTIF);
Any Ideas here?
Using IM Version: ImageMagick-7.1.0
I have included the test images that I am getting the errors on.
zip file download
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用数组,则在执行 cmd 之前声明数组的大小并添加每个参数会更容易。
正如 Esther 所说,另一种选择是在命令内的参数之间添加空格而不传递数组。
如果 IM4Java jar 可用,则更简单的解决方案如下。
If you are using an array, it's easier to declare the size of the array and add each argument before executing the cmd.
Another option, as stated by Esther, is to add a whitespace between parameters within the command and not pass an array.
If the IM4Java jar is available, a more straightforward solution would be the following.