使用coobird Thumbnailator生成缩略图


pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.nihaorz</groupId>
    <artifactId>zxing</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>net.coobird</groupId>
            <artifactId>thumbnailator</artifactId>
            <version>0.4.8</version>
        </dependency>
    </dependencies>

</project>

 

Test.java

import net.coobird.thumbnailator.Thumbnails;

import java.io.File;
import java.io.IOException;

/**
 * Created by Nihaorz on 2017/5/9.
 */
public class Test {
    public static void main(String[] args) throws IOException {
        Thumbnails.of(new File("C:\\Users\\Administrator\\Pictures\\IMG_368845.jpg"))
                .size(160, 160)
                .toFile(new File("C:\\Users\\Administrator\\Pictures\\IMG_368845_min.jpg"));
    }
}

 

更多示例请参见:https://github.com/coobird/thumbnailator/wiki/Examples

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM