java调用AcmeCADConverter软件实现图片转换

之前项目中遇到过将dwg文件转换为jpg的需要,代码整理如下:

String cmd = "C:/AcmeCADConverter/AcmeCADConverter.exe" 
					+ " /r /e /ls /p 3 /f 2 /w 295mm /h 200mm /a 0 /lw 1  "
					+ filePath; // filePath即旧图片路径,比如D:/testPic.dwg
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(cmd);
p.waitFor();// 等待 进程执行结束
String newPath = new String(filePath.replaceFirst("(?i)\\.(dwg|dxf)", ".jpg"));
System.out.println("======图片新路径:= " + newPath);

代码解释:
java通过cmd命令调用AcmeCADConverter软件去转换图片,这里说明一下AcmeCADConverter的相关命令。
/r 以命令模式运行AcmeCADConverter.exe,可以立即转换图片,转换完成后自动退出软件。
/e 自动缩放自动扩展
/ls 使用模板图片尺寸
一般命令都是以/r /e /ls 开关,如果要固定尺寸,可以使用 /r /e /scale 100.0 /margin 0.05
/p 3 图片像素格式。1 – 1_bit format, 2 – gray format, 3 – 256 colors
/f 2 转换jpg格式的图片。数字含义如下
1 – bitmap format(.bmp),
2 – Jpeg format(
.jpg),
3 – GIF format(.gif),
4-- PCX format(
.pcx) ,
5-- TIFF fromat(.tiff),
6–PNG format(
.png),
7–TGA format(.tga),
8- WMF format(
.wmf),
101 – SVG format , (.svg)
102 – HPGL .PLT format , (.plt)
103 – HPGL .HGL format , (.hgl)
104 – PDF format(
.pdf),
105 – Converts more drawing files into one PDF file(.pdf),
109 – PDF (per PDF file for per layout) (
.pdf)
106 – SVGZ (Compressed scalable vector graphics), (.svgz)
107 – CGM (Computer graphics metafile), (
.cgm)
108 – EPS(Encapsulated PostScript), (*.eps)
/w 295mm 图片宽度为295mm
/h 200mm 图片高度为200mm
/a 0 转换形式,数字意义如下:
0 : Always converts model space .
1 : Converts the 1st layout.
2 : Converts the 2nd layout, and so on.
-1 :Converts the current layout.
-2 :Converts all layouts.
-3 :Converts all paper space layouts
/lw 1 Enable the line weight option.
/lw 1 to enable the line weight option.
/lw 0 to disable it (default)

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值