由于上篇poi-tl导出word中携带大量图片, 导致导出word文档过大,考虑压缩图片,故记录
poi-tl导出word, 含表格单元格合并,表格单元格多图合并_xwpftemplate 表格_小菜鸡℡的博客-CSDN博客
1.导包
<dependency> <groupId>net.coobird</groupId> <artifactId>thumbnailator</artifactId> <version>0.4.17</version> </dependency>
2. 代码
java图片流
//压缩图片 BufferedImage bufferedImage = Thumbnails.of(new FileInputStream(picture)) .outputQuality(0.5f)//原图片质量的1/2 .scale(0.25f)//压缩为员图的1/4 .asBufferedImage();
扩展: BufferedImage转换InputStream
BufferedImage bufferedImage = (BufferedImage) dicom.getImage();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage , "jpg", os);
inputStream = new ByteArrayInputStream(os.toByteArray());