java图片压缩生成缩略图

String originalFileName = multipartFile.getOriginalFilename();
/** 获得文件后缀名 **/
String fileExtName = FilenameUtils.getExtension(originalFileName);
byte[] file_buff = multipartFile.getBytes();
InputStream is = multipartFile.getInputStream();
BufferedImage buff;
ByteArrayInputStream inputStream = new ByteArrayInputStream(file_buff);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(file_buff.length);
try {
//生成缩略图

					Thumbnails.of(inputStream)
							.scale(0.75f)
							.outputQuality(0.75f)
							.toOutputStream(outputStream);
					file_buff = outputStream.toByteArray();
					final ByteArrayInputStream swapStream = new ByteArrayInputStream(file_buff);
					buff = ImageIO.read(swapStream);

					swapStream.close();
					inputStream.close();
					outputStream.close();

你可能感兴趣的:(java图片压缩生成缩略图)