Package org.esa.snap.core.util.geotiff
Class IIOUtils
- java.lang.Object
-
- org.esa.snap.core.util.geotiff.IIOUtils
-
public class IIOUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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 aBufferedImage
as the result of decoding a suppliedFile
with anImageReader
chosen automatically from among those currently registered.static IIOImage
readImage(ImageInputStream stream)
Returns aBufferedImage
as the result of decoding a suppliedImageInputStream
with anImageReader
chosen automatically from among those currently registered.static boolean
writeImage(IIOImage iioImage, String formatName, File output)
Writes an image using an arbitraryImageWriter
that supports the given format to aFile
.static boolean
writeImage(IIOImage iioImage, String formatName, ImageOutputStream output)
Writes an image using the an arbitraryImageWriter
that supports the given format to anImageOutputStream
.
-
-
-
Method Detail
-
readImage
public static IIOImage readImage(File input) throws IOException
Returns aBufferedImage
as the result of decoding a suppliedFile
with anImageReader
chosen automatically from among those currently registered. TheFile
is wrapped in anImageInputStream
. If no registeredImageReader
claims to be able to readImage the resulting stream,null
is returned.The current cache settings from
getUseCache
andgetCacheDirectory
will be used to control caching in theImageInputStream
that is created.Note that there is no
readImage
method that takes a filename as aString
; use this method instead after creating aFile
from the filename.This methods does not attempt to locate
ImageReader
s that can readImage directly from aFile
; that may be accomplished usingIIORegistry
andImageReaderSpi
.- Parameters:
input
- aFile
to readImage from.- Returns:
- a
BufferedImage
containing the decoded contents of the input, ornull
. - Throws:
IllegalArgumentException
- ifinput
isnull
.IOException
- if an error occurs during reading.
-
readImage
public static IIOImage readImage(ImageInputStream stream) throws IOException
Returns aBufferedImage
as the result of decoding a suppliedImageInputStream
with anImageReader
chosen automatically from among those currently registered. If no registeredImageReader
claims to be able to readImage the stream,null
is returned.- Parameters:
stream
- anImageInputStream
to readImage from.- Returns:
- a
BufferedImage
containing the decoded contents of the input, ornull
. - Throws:
IllegalArgumentException
- ifstream
isnull
.IOException
- if an error occurs during reading.
-
writeImage
public static boolean writeImage(IIOImage iioImage, String formatName, File output) throws IOException
Writes an image using an arbitraryImageWriter
that supports the given format to aFile
. If there is already aFile
present, its contents are discarded.- Parameters:
iioImage
- the image data to be written.formatName
- aString
containg the informal name of the format.output
- aFile
to be written to.- Returns:
false
if no appropriate writer is found.- Throws:
IllegalArgumentException
- if any parameter isnull
.IOException
- if an error occurs during writing.
-
writeImage
public static boolean writeImage(IIOImage iioImage, String formatName, ImageOutputStream output) throws IOException
Writes an image using the an arbitraryImageWriter
that supports the given format to anImageOutputStream
. The image is written to theImageOutputStream
starting at the current stream pointer, overwriting existing stream data from that point forward, if present.- Parameters:
iioImage
- the image data to be written.formatName
- aString
containg the informal name of the format.output
- anImageOutputStream
to be written to.- Returns:
false
if no appropriate writer is found.- Throws:
IllegalArgumentException
- if any parameter isnull
.IOException
- if an error occurs during writing.
-
getImageWriter
public static ImageWriter getImageWriter(ImageTypeSpecifier imageType, String imageFormatName)
Gets an image writer suitable to be used for the given image type and image format.- Parameters:
imageType
- the type of the image to be written laterimageFormatName
- the image format name, e.g. "TIFF"- Returns:
- a suitable image writer, or
null
if no writer is found
-
getImageWriter
public 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.- Parameters:
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", ornull
- Returns:
- a suitable image writer, or
null
if no writer is found
-
getXML
public static String getXML(IIOMetadata metadata)
-
-