碎碎念
tif格式转jpg格式,本次使用了thumbnailator工具包
其次是java本身的ImageIO类不支持读取tif文件,这里需要用到一个使ImageIO能读取到tif文件的类:
由于 ImageIO 会自动搜索类路径下继承的接口和子类,所以不须要显示调用。彻底无侵入。
ImageIO支持读取tif文件的包
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-tiff</artifactId>
<version>3.4.1</version>
</dependency>
thumbnailator工具包
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
转换代码
这里为了保持图片原貌,同时转换出来,使用jpg保存的时候使用质量最好的outputQuality(1f)
做的,可以去看看thumbnailator的参数
public static void main(String[] args) throws IOException {
BufferedImage tif = ImageIO.read(new File("D:\\001-1.tif"));
Thumbnails
.of(tif)
.outputFormat("jpg")
.scale(1f)
.outputQuality(1f)
.toFile(new File("D:\\001-1.jpg"));
}