Skip to content

Instantly share code, notes, and snippets.

@rankun203
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rankun203/559379839d30c2190db5 to your computer and use it in GitHub Desktop.
Save rankun203/559379839d30c2190db5 to your computer and use it in GitHub Desktop.
Get Cropped image using Scalr.
//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