Created
January 27, 2016 20:57
-
-
Save kirkbackus/2ea6ab20cc57bae3e890 to your computer and use it in GitHub Desktop.
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
String fileType = StringUtils.substringAfterLast(file.getOriginalFilename(), "."); | |
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next(); | |
ImageWriteParam param = writer.getDefaultWriteParam(); | |
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); | |
param.setCompressionQuality(0.70f); | |
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |
writer.setOutput(os); | |
writer.write(null, new IIOImage(bufferedImage, null, null), param); | |
// ImageIO.write(bufferedImage, fileType, os); | |
byte[] imageBytes = os.toByteArray(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment