Java String Format getImageWriter(ImageTypeSpecifier imageType, String imageFormatName)

Here you can find the source of getImageWriter(ImageTypeSpecifier imageType, String imageFormatName)

Description

Gets an image writer suitable to be used for the given image type and image format.

License

Open Source License

Parameter

Parameter Description
imageType the type of the image to be written later
imageFormatName the image format name, e.g. "TIFF"

Return

a suitable image writer, or null if no writer is found

Declaration

public static ImageWriter getImageWriter(ImageTypeSpecifier imageType, String imageFormatName) 

Method Source Code

//package com.java2s;
/*//w  w w  .j  av  a2s. co  m
 * Copyright (C) 2010 Brockmann Consult GmbH (info@brockmann-consult.de)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option)
 * any later version.
 * This program 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 General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, see http://www.gnu.org/licenses/
 */

import javax.imageio.ImageIO;

import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriter;

import java.util.Iterator;

public class Main {
    /**
     * Gets an image writer suitable to be used for the given image type and image format.
     *
     * @param imageType       the type of the image to be written later
     * @param imageFormatName the image format name, e.g. "TIFF"
     *
     * @return a suitable image writer, or <code>null</code> if no writer is found
     */
    public static ImageWriter getImageWriter(ImageTypeSpecifier imageType, String imageFormatName) {
        return getImageWriter(imageType, imageFormatName, null);

    }

    /**
     * Gets an image writer suitable to be used for the given image type, image format and metadata format.
     *
     * @param imageType          the type of the image to be written later
     * @param imageFormatName    the image format name, e.g. "TIFF"
     * @param metadataFormatName the metadata format name, e.g. "com_sun_media_imageio_plugins_tiff_image_1.0", or
     *                           <code>null</code>
     *
     * @return a suitable image writer, or <code>null</code> if no writer is found
     */
    public static ImageWriter getImageWriter(ImageTypeSpecifier imageType, String imageFormatName,
            String metadataFormatName) {

        Iterator writers = ImageIO.getImageWriters(imageType, imageFormatName);
        while (writers.hasNext()) {
            final ImageWriter writer = (ImageWriter) writers.next();
            if (metadataFormatName == null) {
                return writer;
            }
            final String nativeImageMetadataFormatName = writer.getOriginatingProvider()
                    .getNativeImageMetadataFormatName();
            if (metadataFormatName.equals(nativeImageMetadataFormatName)) {
                return writer;
            }
        }

        writers = ImageIO.getImageWriters(imageType, imageFormatName);
        while (writers.hasNext()) {
            final ImageWriter writer = (ImageWriter) writers.next();
            final String[] extraImageMetadataFormatNames = writer.getOriginatingProvider()
                    .getExtraImageMetadataFormatNames();
            for (int i = 0; i < extraImageMetadataFormatNames.length; i++) {
                final String extraImageMetadataFormatName = extraImageMetadataFormatNames[i];
                if (metadataFormatName.equals(extraImageMetadataFormatName)) {
                    return writer;
                }
            }
        }

        return null;
    }
}

Related

  1. getFormattedMessage(final String pattern, final Object[] arguments)
  2. getFormattedString(ResourceBundle b, String key, Object... params)
  3. getFormattedString(String key, Object arg)
  4. getFormattedString(String p_bundleName, String p_key, Locale p_locale, Object[] p_arguments)
  5. getFormatValue(String value, Object[] args)
  6. getImageWriter(String formatName)
  7. getRequriedArgumentCount(MessageFormat msgFormat)
  8. getStylingHyphenFormat(String cssProperties)
  9. getTextAsFormattedLines(String text, int lineLength)