1. 借助ImageMagick工具
下载地址: http://www.imagemagick.org/script/download.php
windows版本:
安装位置指定之后, 默认安装一路到底.
2. 编写java代码
凑成下图的命令行:
代码:
package com.Test.tifTranslateJPG;
public class test {
public static void tiffToJpg(String tifFilePath, String toFilePath){
String command = "E:\\ImageMagick-7.0.11-Q16-HDRI\\magick " + tifFilePath + " " + toFilePath;
System.out.println(command);
cmd(command);
}
public static boolean cmd(String command) {
boolean flag = false;
try {
// 调用系统的cmd
Runtime.getRuntime().exec(command);
flag = true;
} catch (Exception exception) {
exception.printStackTrace();
}
return flag;
}
public static void main(String[] args) {
// E:\ImageMagick-7.0.11-Q16-HDRI\magick D:\test\a.tif D:\test\a.jpg
tiffToJpg("D:\\test\\a.tif", "D:\\test\\a.jpg");
}
}
运行代码之后, 该目标文件夹下就会出现.jpg结尾的图片.