Last active
August 29, 2015 14:01
-
-
Save rankun203/559379839d30c2190db5 to your computer and use it in GitHub Desktop.
Get Cropped image using Scalr.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//get file from Mongo Grid file system. | |
GridFSDBFile file = fileService.getFile(fileId); | |
//将图片文件转换成一个BufferedImage对象 | |
BufferedImage image = ImageIO.read(file.getInputStream()); | |
//执行对应的操作 | |
BufferedImage thumbnail = Scalr.resize(image, 150); | |
//获取文件的格式 | |
response.setContentType(file.getContentType()); | |
//写入最终文件到输出流 | |
ImageIO.write(thumbnail, "jpeg", response.getOutputStream()); | |
//刷新输出流,确保文件发送到浏览器 | |
response.flushBuffer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment