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();            

 

posted @ 2020-05-19 10:21  rubekid  阅读(345)  评论(0编辑  收藏  举报