Programmatically Reducing JPEG file size

后端 未结 4 959
再見小時候
再見小時候 2021-01-12 07:36

Apologies for any ignorance, but I have never worked with jpeg images (let alone any types of images) in Java before.

Supposing I want to send a jpeg image from a we

4条回答
  •  心在旅途
    2021-01-12 07:57

    Another way to reduce image size is to change compression level. You can do that using ImageWriter.

        ImageWriter writer = null;
        Iterator iwi = ImageIO.getImageWritersByFormatName("jpg");
        if (!iwi.hasNext())
            return;
        writer = (ImageWriter) iwi.next();
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
        iwp.setCompressionQuality(compressionQuality);
        writer.setOutput(...);
        writer.write(null, image, iwp);
    

提交回复
热议问题