其他分享
首页 > 其他分享> > 通过 Thumbnails 压缩图片后转 base64

通过 Thumbnails 压缩图片后转 base64

作者:互联网

BASE64Encoder base64Encoder =new BASE64Encoder();
        //存放图片转码后的数据
        String base64EncoderImg = "";
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            Thumbnails.of(img.getInputStream()).scale(0.8F).toOutputStream(out);
            base64EncoderImg = base64Encoder.encode(out.toByteArray());
        } catch (Exception e) {
            e.printStackTrace();
        }

Thumbnails依赖

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

 

标签:base64Encoder,Thumbnails,压缩,base64,BASE64Encoder,ByteArrayOutputStream,new,out
来源: https://www.cnblogs.com/mikemhm/p/11951781.html