Thumbnails压缩图片后转为Base64

public String compressToBASE64(InputStream inputStream){
     
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	Thumbnails.of(inputStream)
			.scale(1)
			.outputQuality(0.5f)
			// 导出到 ByteArrayOutputStream 中
			.toOutputStream(out);
	//将ByteArrayOutputStream转为base64
	return Base64.getEncoder().encodeToString(out.toByteArray());
}

你可能感兴趣的:(Java)