zoukankan      html  css  js  c++  java
  • tif格式图片转换为gif、png、jpg格式(Java实战)

    tif格式图片转换为gif、png、jpg格式(Java实战)

    tif的格式的图片通常很大,且不能被浏览器直接预览,一般处理方案都是服务端将其转换为jpg、png等格式的图片,再由前端进行展示。

    网络上也有很多转换格式的样例,但大都比较麻烦,本次实践使用开源组件 thumbnailator 来实现图片格式转换,更为便捷。

    引用依赖

    <dependency>
        <groupId>net.coobird</groupId>
        <artifactId>thumbnailator</artifactId>
        <version>0.4.8</version>
    </dependency>
    

    实战

    tif图片样例:
    image

    存储大小:18.4MB

    实战代码:

    public static void main(String[] args) throws IOException {
    
        /*------------ 转换为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");
    
        /*------------ 转换为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");
    
        /*------------ 转换为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");
    }
    

    转换后:
    image

    image

    可以看到图片肉眼看上去没有什么变化。

  • 相关阅读:
    Python算术运算符
    Python数据类型转换
    Linux下Tomcat启动设置debug模式启动
    FastJson之JsonObject, JsonString, JavaBean,List快速转换
    Linux 之 ./configure --prefix 命令
    JS中Ajax的同步和异步
    MySql 中 case when then else end 的用法
    Linux中CentOS6.5 64位 系统下安装docker步骤
    Linux常用命令 查找文件
    微信小程序中事件
  • 原文地址:https://www.cnblogs.com/keeya/p/14335621.html
Copyright © 2011-2022 走看看