使用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

原文地址:https://www.cnblogs.com/nihaorz/p/6831717.html