Here you can find the source of getImageWriter(ImageTypeSpecifier imageType, String imageFormatName)
Parameter | Description |
---|---|
imageType | the type of the image to be written later |
imageFormatName | the image format name, e.g. "TIFF" |
null
if no writer is found
public static ImageWriter getImageWriter(ImageTypeSpecifier imageType, String imageFormatName)
//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; } }