BufferedImage thumbImage = new BufferedImage( thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB );
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR );
graphics2D.drawImage( image, 0, 0, thumbWidth, thumbHeight, null );
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( outputStream );
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam( thumbImage );
int quality = 70;
quality = Math.max( 0, Math.min( quality, 100 ) );
param.setQuality( (float) quality / 100.0f, false );
encoder.setJPEGEncodeParam( param );
encoder.encode( thumbImage );
}
catch (IOException ex) {
logger.error( ex.getMessage(), ex );
}
catch (InterruptedException ex) {