Java ImageIO Usage guessCompressionRatio(final ImageReaderWriterSpi spi)

Here you can find the source of guessCompressionRatio(final ImageReaderWriterSpi spi)

Description

Guesses the compression ratio for the given image format.

License

Open Source License

Parameter

Parameter Description
spi The image reader or writer provider.

Return

The inverse of a guess of compression ratio (1 is uncompressed), or 0 if unknown.

Declaration

public static int guessCompressionRatio(final ImageReaderWriterSpi spi) 

Method Source Code

//package com.java2s;
/*/*from   ww w  .  ja  v  a 2  s .  c  om*/
 *    Geotoolkit.org - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2009-2012, Open Source Geospatial Foundation (OSGeo)
 *    (C) 2009-2012, Geomatys
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

import javax.imageio.spi.ImageReaderWriterSpi;

public class Main {
    /**
     * Guesses the compression ratio for the given image format. This is very approximative
     * and used only in order to have some order of magnitude.
     *
     * @param  spi The image reader or writer provider.
     * @return The inverse of a guess of compression ratio (1 is uncompressed), or 0 if unknown.
     */
    public static int guessCompressionRatio(final ImageReaderWriterSpi spi) {
        if (spi != null) {
            for (final String format : spi.getFormatNames()) {
                if (format.equalsIgnoreCase("png")) {
                    return 4;
                }
                if (format.equalsIgnoreCase("jpeg")) {
                    return 8;
                }
                if (format.equalsIgnoreCase("tiff")) {
                    // TIFF are uncompressed unless explicitly specified.
                    return 1;
                }
                if (format.equalsIgnoreCase("bmp")
                        || format.equalsIgnoreCase("raw")) {
                    return 1;
                }
            }
        }
        return 0;
    }
}

Related

  1. closeEL(ImageInputStream iis)
  2. createAsciiField(int number, String name, String val)
  3. createImageWriteParam(ImageWriter writer, float quality)
  4. deregisterProvider( final ServiceRegistry registry, final IIOServiceProvider provider, final Class category)
  5. getParams(ImageWriter writer)
  6. lookupProviderByName( final ServiceRegistry registry, final String providerClassName)
  7. setCompressionQuality(ImageWriteParam params, int quality)