java jpg图片按质量保存
File distImage = new File(distPath); ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next(); ImageWriteParam jpgWriteParam = jpgWriter.getDefaultWriteParam(); jpgWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpgWriteParam.setCompressionQuality(Constant.config.getCompressionQuality()); jpgWriter.setOutput(ImageIO.createImageOutputStream(distImage)); IIOImage outputImage = new IIOImage(newImage, null, null); jpgWriter.write(null, outputImage, jpgWriteParam); jpgWriter.dispose();