public class IIOUtils extends Object
Modifier and Type | Method and Description |
---|---|
static ImageWriter |
getImageWriter(ImageTypeSpecifier imageType,
String imageFormatName)
Gets an image writer suitable to be used for the given image type and image format.
|
static ImageWriter |
getImageWriter(ImageTypeSpecifier imageType,
String imageFormatName,
String metadataFormatName)
Gets an image writer suitable to be used for the given image type, image format and metadata format.
|
static String |
getXML(IIOMetadata metadata) |
static IIOImage |
readImage(File input)
Returns a
BufferedImage as the result of decoding a supplied File with an
ImageReader chosen automatically from among those currently registered. |
static IIOImage |
readImage(ImageInputStream stream)
Returns a
BufferedImage as the result of decoding a supplied ImageInputStream with an
ImageReader chosen automatically from among those currently registered. |
static boolean |
writeImage(IIOImage iioImage,
String formatName,
File output)
Writes an image using an arbitrary
ImageWriter that supports the given format to a
File . |
static boolean |
writeImage(IIOImage iioImage,
String formatName,
ImageOutputStream output)
Writes an image using the an arbitrary
ImageWriter that supports the given format to an
ImageOutputStream . |
public static IIOImage readImage(File input) throws IOException
BufferedImage
as the result of decoding a supplied File
with an
ImageReader
chosen automatically from among those currently registered. The File
is
wrapped in an ImageInputStream
. If no registered ImageReader
claims to be able to
readImage the resulting stream, null
is returned.
The current cache settings from getUseCache
and getCacheDirectory
will be used to
control caching in the ImageInputStream
that is created.
Note that there is no readImage
method that takes a filename as a String
; use this
method instead after creating a File
from the filename.
This methods does not attempt to locate ImageReader
s that can readImage directly from a
File
; that may be accomplished using IIORegistry
and ImageReaderSpi
.
input
- a File
to readImage from.BufferedImage
containing the decoded contents of the input, or null
.IllegalArgumentException
- if input
is null
.IOException
- if an error occurs during reading.public static IIOImage readImage(ImageInputStream stream) throws IOException
BufferedImage
as the result of decoding a supplied ImageInputStream
with an
ImageReader
chosen automatically from among those currently registered. If no registered
ImageReader
claims to be able to readImage the stream, null
is returned.stream
- an ImageInputStream
to readImage from.BufferedImage
containing the decoded contents of the input, or null
.IllegalArgumentException
- if stream
is null
.IOException
- if an error occurs during reading.public static boolean writeImage(IIOImage iioImage, String formatName, File output) throws IOException
ImageWriter
that supports the given format to a
File
. If there is already a File
present, its contents are discarded.iioImage
- the image data to be written.formatName
- a String
containg the informal name of the format.output
- a File
to be written to.false
if no appropriate writer is found.IllegalArgumentException
- if any parameter is null
.IOException
- if an error occurs during writing.public static boolean writeImage(IIOImage iioImage, String formatName, ImageOutputStream output) throws IOException
ImageWriter
that supports the given format to an
ImageOutputStream
. The image is written to the ImageOutputStream
starting at the
current stream pointer, overwriting existing stream data from that point forward, if present.iioImage
- the image data to be written.formatName
- a String
containg the informal name of the format.output
- an ImageOutputStream
to be written to.false
if no appropriate writer is found.IllegalArgumentException
- if any parameter is null
.IOException
- if an error occurs during writing.public static ImageWriter getImageWriter(ImageTypeSpecifier imageType, String imageFormatName)
imageType
- the type of the image to be written laterimageFormatName
- the image format name, e.g. "TIFF"null
if no writer is foundpublic static ImageWriter getImageWriter(ImageTypeSpecifier imageType, String imageFormatName, String metadataFormatName)
imageType
- the type of the image to be written laterimageFormatName
- the image format name, e.g. "TIFF"metadataFormatName
- the metadata format name, e.g. "com_sun_media_imageio_plugins_tiff_image_1.0", or
null
null
if no writer is foundpublic static String getXML(IIOMetadata metadata)
Copyright © 2014–2017 European Space Agency (ESA). All rights reserved.