Java how to set jpg quality

后端 未结 3 378
既然无缘
既然无缘 2021-01-12 02:25

Just wanting to get some code edited so that the output jpg quality isn\'t the default low quality setting that

try
        {
            ImageIO.write(var6         


        
3条回答
  •  天涯浪人
    2021-01-12 02:55

    Finally did it with this code ...

    try
    {
    
        ImageOutputStream  ios =  ImageIO.createImageOutputStream(var7);
        Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
        ImageWriter writer = iter.next();
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwp.setCompressionQuality(0.85f);
        writer.setOutput(ios);
        writer.write(null, new IIOImage(var6,null,null),iwp);
        writer.dispose();
    
        //ImageIO.write(var6, "jpg", var7);
    }
    

提交回复
热议问题