is new.
java.lang.Objectjavax.imageio.ImageIO
public final class ImageIO
A class containing static convenience methods for locating ImageReaders and ImageWriters, and performing simple encoding and decoding.
| Method Summary | |
|---|---|
| static ImageInputStream |
createImageInputStream
(
Object
input) Returns an ImageInputStream that will take its input from the given Object. |
| static ImageOutputStream |
createImageOutputStream
(
Object
output) Returns an ImageOutputStream that will send its output to the given Object. |
| static File |
getCacheDirectory
() Returns the current value set by setCacheDirectory, or null if no explicit setting has been made. |
| static ImageReader |
getImageReader
(
ImageWriter
writer) Returns an ImageReadercorresponding to the given ImageWriter, if there is one, or null if the plug-in for this ImageWriter does not specify a corresponding ImageReader, or if the given ImageWriter is not registered. |
| static Iterator < ImageReader > |
getImageReaders
(
Object
input) Returns an Iterator containing all currently registered ImageReaders that claim to be able to decode the supplied Object, typically an ImageInputStream. |
| static Iterator < ImageReader > |
getImageReadersByFormatName
(
String
formatName) Returns an Iterator containing all currently registered ImageReaders that claim to be able to decode the named format. |
| static Iterator < ImageReader > |
getImageReadersByMIMEType
(
String
MIMEType) Returns an Iterator containing all currently registered ImageReaders that claim to be able to decode files with the given MIME type. |
| static Iterator < ImageReader > |
getImageReadersBySuffix
(
String
fileSuffix) Returns an Iterator containing all currently registered ImageReaders that claim to be able to decode files with the given suffix. |
| static Iterator < ImageTranscoder > |
getImageTranscoders
(
ImageReader
reader,
ImageWriter
writer) Returns an Iterator containing all currently registered ImageTranscoders that claim to be able to transcode between the metadata of the given ImageReader and ImageWriter. |
| static ImageWriter |
getImageWriter
(
ImageReader
reader) Returns an ImageWritercorresponding to the given ImageReader, if there is one, or null if the plug-in for this ImageReader does not specify a corresponding ImageWriter, or if the given ImageReader is not registered. |
| static Iterator < ImageWriter > |
getImageWriters
(
ImageTypeSpecifier
type,
String
formatName) Returns an Iterator containing all currently registered ImageWriters that claim to be able to encode images of the given layout (specified using an ImageTypeSpecifier) in the given format. |
| static Iterator < ImageWriter > |
getImageWritersByFormatName
(
String
formatName) Returns an Iterator containing all currently registered ImageWriters that claim to be able to encode the named format. |
| static Iterator < ImageWriter > |
getImageWritersByMIMEType
(
String
MIMEType) Returns an Iterator containing all currently registered ImageWriters that claim to be able to encode files with the given MIME type. |
| static Iterator < ImageWriter > |
getImageWritersBySuffix
(
String
fileSuffix) Returns an Iterator containing all currently registered ImageWriters that claim to be able to encode files with the given suffix. |
static
String
|
getReaderFileSuffixes
()
Returns an array of Strings listing all of the file suffixes associated with the formats understood by the current set of registered readers.
|
| static String [] |
getReaderFormatNames
() Returns an array of Strings listing all of the informal format names understood by the current set of registered readers. |
| static String [] |
getReaderMIMETypes
() Returns an array of Strings listing all of the MIME types understood by the current set of registered readers. |
| static boolean |
getUseCache
() Returns the current value set by setUseCache, or true if no explicit setting has been made. |
static
String
|
getWriterFileSuffixes
()
Returns an array of Strings listing all of the file suffixes associated with the formats understood by the current set of registered writers.
|
| static String [] |
getWriterFormatNames
() Returns an array of Strings listing all of the informal format names understood by the current set of registered writers. |
| static String [] |
getWriterMIMETypes
() Returns an array of Strings listing all of the MIME types understood by the current set of registered writers. |
| static BufferedImage |
read
(
File
input) Returns a BufferedImage as the result of decoding a supplied File with an ImageReader chosen automatically from among those currently registered. |
| static BufferedImage |
read
(
ImageInputStream
stream) Returns a BufferedImage as the result of decoding a supplied ImageInputStream with an ImageReader chosen automatically from among those currently registered. |
| static BufferedImage |
read
(
InputStream
input) Returns a BufferedImage as the result of decoding a supplied InputStream with an ImageReader chosen automatically from among those currently registered. |
| static BufferedImage |
read
(
URL
input) Returns a BufferedImage as the result of decoding a supplied URL with an ImageReader chosen automatically from among those currently registered. |
| static void |
scanForPlugins
() Scans for plug-ins on the application class path, loads their service provider classes, and registers a service provider instance for each one found with the IIORegistry. |
| static void |
setCacheDirectory
(
File
cacheDirectory) Sets the directory where cache files are to be created. |
| static void |
setUseCache
(boolean useCache) Sets a flag indicating whether a disk-based cache file should be used when creating ImageInputStreams and ImageOutputStreams. |
| static boolean |
write
(
RenderedImage
im,
String
formatName,
File
output) Writes an image using an arbitrary ImageWriter that supports the given format to a File. |
| static boolean |
write
(
RenderedImage
im,
String
formatName,
ImageOutputStream
output) Writes an image using the an arbitrary ImageWriter that supports the given format to an ImageOutputStream. |
| static boolean |
write
(
RenderedImage
im,
String
formatName,
OutputStream
output) Writes an image using an arbitrary ImageWriter that supports the given format to an OutputStream. |
| Methods inherited from class java.lang. Object |
|---|
| clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
| Method Detail |
|---|
public static void scanForPlugins()
This method is needed because the application class path can theoretically change, or additional plug-ins may become available. Rather than re-scanning the classpath on every invocation of the API, the class path is scanned automatically only on the first invocation. Clients can call this method to prompt a re-scan. Thus this method need only be invoked by sophisticated applications which dynamically make new plug-ins available at runtime.
The getResources method of the context ClassLoader is used locate JAR files containing files named META-INF/services/javax.imageio.spi. classname , where classname is one of ImageReaderSpi, ImageWriterSpi, ImageTranscoderSpi, ImageInputStreamSpi, or ImageOutputStreamSpi, along the application class path.
The contents of the located files indicate the names of actual implementation classes which implement the aforementioned service provider interfaces; the default class loader is then used to load each of these classes and to instantiate an instance of each class, which is then placed into the registry for later retrieval.
The exact set of locations searched depends on the implementation of the Java runtime enviroment.
public static void setUseCache(boolean useCache)
When reading from a standard InputStream>, it may be necessary to save previously read information in a cache since the underlying stream does not allow data to be re-read. Similarly, when writing to a standard OutputStream, a cache may be used to allow a previously written value to be changed before flushing it to the final destination.
The cache may reside in main memory or on disk. Setting this flag to false disallows the use of disk for future streams, which may be advantageous when working with small images, as the overhead of creating and destroying files is removed.
On startup, the value is set to true.
public static boolean getUseCache()
public static void setCacheDirectory(File cacheDirectory)
public static File getCacheDirectory()
public static ImageInputStream createImageInputStream(Object input)
throws IOException
The current cache settings from getUseCacheand getCacheDirectory will be used to control caching.
public static ImageOutputStream createImageOutputStream(Object output)
throws IOException
The current cache settings from getUseCacheand getCacheDirectory will be used to control caching.
public static String[] getReaderFormatNames()
public static String[] getReaderMIMETypes()
getReaderFileSuffixes
public static
String
[]
getReaderFileSuffixes
()
Returns an array of Strings listing all of the file suffixes associated with the formats understood by the current set of registered readers.
Returns:
an array of Strings.
Since:
1.6
public static Iterator<ImageReader> getImageReaders(Object input)
The stream position is left at its prior position upon exit from this method.
public static Iterator<ImageReader> getImageReadersByFormatName(String formatName)
public static Iterator<ImageReader> getImageReadersBySuffix(String fileSuffix)
public static Iterator<ImageReader> getImageReadersByMIMEType(String MIMEType)
public static String[] getWriterFormatNames()
public static String[] getWriterMIMETypes()
getWriterFileSuffixes
public static
String
[]
getWriterFileSuffixes
()
Returns an array of Strings listing all of the file suffixes associated with the formats understood by the current set of registered writers.
Returns:
an array of Strings.
Since:
1.6
public static Iterator<ImageWriter> getImageWritersByFormatName(String formatName)
public static Iterator<ImageWriter> getImageWritersBySuffix(String fileSuffix)
public static Iterator<ImageWriter> getImageWritersByMIMEType(String MIMEType)
public static ImageWriter getImageWriter(ImageReader reader)
public static ImageReader getImageReader(ImageWriter writer)
public static Iterator<ImageWriter> getImageWriters(ImageTypeSpecifier type,
String formatName)
public static Iterator<ImageTranscoder> getImageTranscoders(ImageReader reader,
ImageWriter writer)
public static BufferedImage read(File input)
throws IOException
The current cache settings from getUseCacheand getCacheDirectory will be used to control caching in the ImageInputStream that is created.
Note that there is no read method that takes a filename as a String; use this method instead after creating a File from the filename.
This
method
methods
does not attempt to locate ImageReaders that can read directly from a File; that may be accomplished using IIORegistry and ImageReaderSpi.
public static BufferedImage read(InputStream input)
throws IOException
The current cache settings from getUseCacheand getCacheDirectory will be used to control caching in the ImageInputStream that is created.
This
method
methods
does not attempt to locate ImageReaders that can read directly from an InputStream; that may be accomplished using IIORegistry and ImageReaderSpi.
This method does not close the provided InputStream after the read operation has completed; it is the responsibility of the caller to close the stream, if desired.
public static BufferedImage read(URL input)
throws IOException
The current cache settings from getUseCacheand getCacheDirectory will be used to control caching in the ImageInputStream that is created.
This
method
methods
does not attempt to locate ImageReaders that can read directly from a URL; that may be accomplished using IIORegistry and ImageReaderSpi.
public static BufferedImage read(ImageInputStream stream)
throws IOException
Unlike most other methods in this class, this method does close the provided ImageInputStream after the read operation has completed, unless null is returned, in which case this method does not close the stream.
public static boolean write(RenderedImage im,
String formatName,
ImageOutputStream output)
throws IOException
This method does not close the provided ImageOutputStream after the write operation has completed; it is the responsibility of the caller to close the stream, if desired.
public static boolean write(RenderedImage im,
String formatName,
File output)
throws IOException
public static boolean write(RenderedImage im,
String formatName,
OutputStream output)
throws IOException
This method does not close the provided OutputStream after the write operation has completed; it is the responsibility of the caller to close the stream, if desired.
The current cache settings from getUseCacheand getCacheDirectory will be used to control caching.