Java ImageIO Usage setCompressionQuality(ImageWriteParam params, int quality)

Here you can find the source of setCompressionQuality(ImageWriteParam params, int quality)

Description

set Compression Quality

License

Open Source License

Declaration

private static void setCompressionQuality(ImageWriteParam params, int quality) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.imageio.ImageWriteParam;

public class Main {
    private static void setCompressionQuality(ImageWriteParam params, int quality) {
        if (quality <= 0) {
            quality = 1;/* w w  w.  ja  v  a 2  s .  com*/
        }

        if (quality > 100) {
            quality = 100;
        }

        try {
            params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            params.setCompressionQuality((float) quality / 100f);
        } catch (Exception e) {
            // DO nothing since compression not supported
        }
    }
}

Related

  1. createImageWriteParam(ImageWriter writer, float quality)
  2. deregisterProvider( final ServiceRegistry registry, final IIOServiceProvider provider, final Class category)
  3. getParams(ImageWriter writer)
  4. guessCompressionRatio(final ImageReaderWriterSpi spi)
  5. lookupProviderByName( final ServiceRegistry registry, final String providerClassName)