List of usage examples for javax.imageio ImageWriteParam MODE_DISABLED
int MODE_DISABLED
To view the source code for javax.imageio ImageWriteParam MODE_DISABLED.
Click Source Link
From source file:ImageUtil.java
/** * store BufferedImage to file/*from w ww .j a v a 2 s .co m*/ * @param image BufferedImage * @param outputFile output image file * @param quality quality of output image * @return true success, else fail */ public static boolean storeImage(BufferedImage image, File outputFile, float quality) { try { //reconstruct folder structure for image file output if (outputFile.getParentFile() != null && !outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } if (outputFile.exists()) { outputFile.delete(); } //get image file suffix String extName = "png"; //get registry ImageWriter for specified image suffix Iterator writers = ImageIO.getImageWritersByFormatName(extName); ImageWriter imageWriter = (ImageWriter) writers.next(); //set image output params ImageWriteParam params = new JPEGImageWriteParam(null); params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); params.setCompressionQuality(quality); params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DISABLED); params.setDestinationType(new ImageTypeSpecifier(IndexColorModel.getRGBdefault(), IndexColorModel.getRGBdefault().createCompatibleSampleModel(16, 16))); //writer image to file ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(outputFile); imageWriter.setOutput(imageOutputStream); imageWriter.write(null, new IIOImage(image, null, null), params); imageOutputStream.close(); imageWriter.dispose(); return true; } catch (Exception e) { e.printStackTrace(); } return false; }