Created
July 1, 2012 08:25
-
-
Save worthlesscog/3027556 to your computer and use it in GitHub Desktop.
Image compress and save
This file contains hidden or 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
BufferedImage scaledImage = scale(sourceImage, width, height, SMOOTHING_STEPS); | |
ByteArrayOutputStream buffer = new ByteArrayOutputStream(1024 * 1024); | |
ImageOutputStream stream = ImageIO.createImageOutputStream(new BufferedOutputStream(buffer)); | |
float percentage = quality; | |
do { | |
buffer.reset(); | |
buildImage(scaledImage, width, height, imageType, stream, percentage); | |
quality = percentage; | |
percentage -= 0.005f; | |
} while (buffer.size() > maxSize); | |
buffer.writeTo(new FileOutputStream(target)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment