Created
May 25, 2013 19:47
-
-
Save xtraclass/5650524 to your computer and use it in GitHub Desktop.
Java: saves a JPEG Buffered Image to a file. Uses the old Sun packages :-)
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
import com.sun.image.codec.jpeg.*; | |
... | |
public static void saveImageToFile( BufferedImage image, File file ) | |
throws IOException | |
{ | |
if ( image == null || file == null ) return; | |
file.delete(); | |
BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream( file ) ); | |
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( out ); | |
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam( image ); | |
param.setQuality( 1, false ); | |
encoder.setJPEGEncodeParam( param ); | |
encoder.encode( image ); | |
out.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment