maven依赖
<!-- 压缩图片jar --> <dependency> <groupId>net.coobird</groupId> <artifactId>thumbnailator</artifactId> <version>0.4.8</version> </dependency>
详细代码
前端使用ajaxfileupload上传,Java框架springmvc,接受文件流使用
CommonsMultipartFile,
(
CommonsMultipartFile file
)
//控制图片的尺寸
BufferedImage image = Thumbnails.of(file.getInputStream()).size(1080,1920).asBufferedImage(); //BufferedImage 转 InputStream ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(image,"png",os); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(os.toByteArray());
result = oSSFileUtil.uploadFileStream(byteArrayInputStream, uploadPath);
详细参考http://blog.csdn.net/chenleixing/article/details/44685817;供自己日后参考。
版权声明:本文为u010792850原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。