Java中tif转png,tif格式图片转换为gif、png、jpg格式(Java实战)
tif的格式的圖片通常很大,且不能被瀏覽器直接預(yù)覽,一般處理方案都是服務(wù)端將其轉(zhuǎn)換為jpg、png等格式的圖片,再由前端進(jìn)行展示。
網(wǎng)絡(luò)上也有很多轉(zhuǎn)換格式的樣例,但大都比較麻煩,本次實踐使用開源組件 thumbnailator 來實現(xiàn)圖片格式轉(zhuǎn)換,更為便捷。
net.coobird
thumbnailator
0.4.8
tif圖片樣例:
存儲大小:18.4MB
實戰(zhàn)代碼:public?static?void?main(String[]?args)?throws?IOException?{????/*------------?轉(zhuǎn)換為jpg?-------------*/
Thumbnails.of(new?File("/Users/axin/IdeaProjects/axin-framework/world/src/main/java/com/axin/world/picTest/tifdemo2.tiff"))????????????.size(1440,?2560)????????????.outputFormat("jpg")????????????.toFile("image-conver.jpg");????/*------------?轉(zhuǎn)換為gif?-------------*/
Thumbnails.of(new?File("/Users/axin/IdeaProjects/axin-framework/world/src/main/java/com/axin/world/picTest/tifdemo2.tiff"))????????????.size(1440,?2560)????????????.outputFormat("gif")????????????.toFile("image-conver2.gif");????/*------------?轉(zhuǎn)換為png?-------------*/
Thumbnails.of(new?File("/Users/axin/IdeaProjects/axin-framework/world/src/main/java/com/axin/world/picTest/tifdemo2.tiff"))????????????.size(1440,?2560)????????????.outputFormat("png")????????????.toFile("image-conver.png");
}
轉(zhuǎn)換后:
可以看到圖片肉眼看上去沒有什么變化。
總結(jié)
以上是生活随笔為你收集整理的Java中tif转png,tif格式图片转换为gif、png、jpg格式(Java实战)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python Pillow批量转换tif
- 下一篇: java美元兑换,(Java实现) 美元