|
JSR-209 (Final Release) | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.imageio.ImageIO
A class containing static convenience methods for locating
ImageReader
s and ImageWriter
s, and
performing simple encoding and decoding.
Note:
JSR-209 does not include the javax.imageio.spi package in
this release. Compliant implementations of JSR-209 will need
to implement ImageReaders and ImageWriters for the supported
formats such that they are available to applications either
through the ImageIO class or the creation of ImageInputStream
or ImageOutputStream.
Method Summary | |
static ImageInputStream |
createImageInputStream(java.lang.Object input)
Returns an ImageInputStream that will take its
input from the given Object . |
static ImageOutputStream |
createImageOutputStream(java.lang.Object output)
Returns an ImageOutputStream that will send its
output to the given Object . |
static java.io.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 ImageReader corresponding to the given
ImageWriter , if there is one, or null . |
static java.util.Iterator |
getImageReaders(java.lang.Object input)
Returns an Iterator containing all
ImageReader s that claim to be able to
decode the supplied Object , typically an
ImageInputStream . |
static java.util.Iterator |
getImageReadersByFormatName(java.lang.String formatName)
Returns an Iterator containing all
ImageReader s that claim to be able to
decode the named format. |
static java.util.Iterator |
getImageReadersByMIMEType(java.lang.String MIMEType)
Returns an Iterator containing all
ImageReader s that claim to be able to
decode files with the given MIME type. |
static java.util.Iterator |
getImageReadersBySuffix(java.lang.String fileSuffix)
Returns an Iterator containing all
ImageReader s that claim to be able to
decode files with the given suffix. |
static ImageWriter |
getImageWriter(ImageReader reader)
Returns an ImageWriter corresponding to the given
ImageReader , if there is one, or null . |
static java.util.Iterator |
getImageWriters(ImageTypeSpecifier type,
java.lang.String formatName)
Returns an Iterator containing all
ImageWriter s that claim to be able to
encode images of the given layout (specified using an
ImageTypeSpecifier ) in the given format. |
static java.util.Iterator |
getImageWritersByFormatName(java.lang.String formatName)
Returns an Iterator containing all
ImageWriter s that claim to be able to
encode the named format. |
static java.util.Iterator |
getImageWritersByMIMEType(java.lang.String MIMEType)
Returns an Iterator containing all
ImageWriter s that claim to be able to
encode files with the given MIME type. |
static java.util.Iterator |
getImageWritersBySuffix(java.lang.String fileSuffix)
Returns an Iterator containing all
ImageWriter s that claim to be able to
encode files with the given suffix. |
static java.lang.String[] |
getReaderFormatNames()
Returns an array of String s listing all of the
informal format names |
static java.lang.String[] |
getReaderMIMETypes()
Returns an array of String s listing all of the
MIME types. |
static boolean |
getUseCache()
Returns the current value set by setUseCache , or
true if no explicit setting has been made. |
static java.lang.String[] |
getWriterFormatNames()
Returns an array of String s listing all of the
informal format names understood by the current set of
writers. |
static java.lang.String[] |
getWriterMIMETypes()
Returns an array of String s listing all of the
MIME types understood by the current set of
writers. |
static BufferedImage |
read(java.io.File input)
Returns a BufferedImage as the result of decoding
a supplied File with an ImageReader
The File is wrapped in an ImageInputStream . |
static BufferedImage |
read(ImageInputStream stream)
Returns a BufferedImage as the result of decoding
a supplied ImageInputStream with an
ImageReader . |
static BufferedImage |
read(java.io.InputStream input)
Returns a BufferedImage as the result of decoding
a supplied InputStream with an ImageReader . |
static BufferedImage |
read(java.net.URL input)
Returns a BufferedImage as the result of decoding
a supplied URL with an ImageReader
An InputStream is obtained from the URL ,
which is wrapped in an ImageInputStream . |
static void |
setCacheDirectory(java.io.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 ImageInputStream s and
ImageOutputStream s. |
static boolean |
write(RenderedImage im,
java.lang.String formatName,
java.io.File output)
Writes an image using an arbitrary ImageWriter
that supports the given format to a File . |
static boolean |
write(RenderedImage im,
java.lang.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,
java.lang.String formatName,
java.io.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 setUseCache(boolean useCache)
ImageInputStream
s and
ImageOutputStream
s.
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
.
useCache
- a boolean
indicating whether a
cache file should be used, in cases where it is optional.getUseCache()
public static boolean getUseCache()
setUseCache
, or
true
if no explicit setting has been made.
ImageInputStream
s and
ImageOutputStream
s.setUseCache(boolean)
public static void setCacheDirectory(java.io.File cacheDirectory)
null
indicates that the system-dependent
default temporary-file directory is to be used. If
getUseCache
returns false, this value is ignored.
cacheDirectory
- a File
specifying a directory.
java.lang.SecurityException
- if the security manager denies
access to the directory.
java.lang.IllegalArgumentException
- if cacheDir
is
non-null
but is not a directory.File.createTempFile(String, String, File)
,
getCacheDirectory()
public static java.io.File getCacheDirectory()
setCacheDirectory
, or null
if no
explicit setting has been made.
File
indicating the directory where
cache files will be created, or null
to indicate
the system-dependent default temporary-file directory.setCacheDirectory(java.io.File)
public static ImageInputStream createImageInputStream(java.lang.Object input) throws java.io.IOException
ImageInputStream
that will take its
input from the given Object
.
The current cache settings from getUseCache
and
getCacheDirectory
will be used to control caching.
input
- an Object
to be used as an input
source, such as a File
, readable
RandomAccessFile
, or InputStream
.
ImageInputStream
, or null
.
java.lang.IllegalArgumentException
- if input
is null
.
java.io.IOException
- if a cache file is needed but cannot be
created.public static ImageOutputStream createImageOutputStream(java.lang.Object output) throws java.io.IOException
ImageOutputStream
that will send its
output to the given Object
.
The current cache settings from getUseCache
and
getCacheDirectory
will be used to control caching.
output
- an Object
to be used as an output
destination, such as a File
, writable
RandomAccessFile
, or OutputStream
.
ImageOutputStream
, or
null
.
java.lang.IllegalArgumentException
- if output
is
null
.
java.io.IOException
- if a cache file is needed but cannot be
created.public static java.lang.String[] getReaderFormatNames()
String
s listing all of the
informal format names
String
s.public static java.lang.String[] getReaderMIMETypes()
String
s listing all of the
MIME types.
String
s.public static java.util.Iterator getImageReaders(java.lang.Object input)
Iterator
containing all
ImageReader
s that claim to be able to
decode the supplied Object
, typically an
ImageInputStream
.
The stream position is left at its prior position upon exit from this method.
input
- an ImageInputStream
or other
Object
containing encoded image data.
Iterator
containing ImageReader
s.
java.lang.IllegalArgumentException
- if input
is
null
.public static java.util.Iterator getImageReadersByFormatName(java.lang.String formatName)
Iterator
containing all
ImageReader
s that claim to be able to
decode the named format.
formatName
- a String
containing the informal
name of a format (e.g., "jpeg" or "tiff".
Iterator
containing
ImageReader
s.
java.lang.IllegalArgumentException
- if formatName
is null
.public static java.util.Iterator getImageReadersBySuffix(java.lang.String fileSuffix)
Iterator
containing all
ImageReader
s that claim to be able to
decode files with the given suffix.
fileSuffix
- a String
containing a file
suffix (e.g., "jpg" or "tiff").
Iterator
containing
ImageReader
s.
java.lang.IllegalArgumentException
- if fileSuffix
is null
.public static java.util.Iterator getImageReadersByMIMEType(java.lang.String MIMEType)
Iterator
containing all
ImageReader
s that claim to be able to
decode files with the given MIME type.
MIMEType
- a String
containing a file
suffix (e.g., "image/jpeg" or "image/x-bmp").
Iterator
containing
ImageReader
s.
java.lang.IllegalArgumentException
- if MIMEType
is
null
.public static java.lang.String[] getWriterFormatNames()
String
s listing all of the
informal format names understood by the current set of
writers.
String
s.public static java.lang.String[] getWriterMIMETypes()
String
s listing all of the
MIME types understood by the current set of
writers.
String
s.public static java.util.Iterator getImageWritersByFormatName(java.lang.String formatName)
Iterator
containing all
ImageWriter
s that claim to be able to
encode the named format.
formatName
- a String
containing the informal
name of a format (e.g., "jpeg" or "tiff".
Iterator
containing
ImageWriter
s.
java.lang.IllegalArgumentException
- if formatName
is
null
.public static java.util.Iterator getImageWritersBySuffix(java.lang.String fileSuffix)
Iterator
containing all
ImageWriter
s that claim to be able to
encode files with the given suffix.
fileSuffix
- a String
containing a file
suffix (e.g., "jpg" or "tiff").
Iterator
containing ImageWriter
s.
java.lang.IllegalArgumentException
- if fileSuffix
is
null
.public static java.util.Iterator getImageWritersByMIMEType(java.lang.String MIMEType)
Iterator
containing all
ImageWriter
s that claim to be able to
encode files with the given MIME type.
MIMEType
- a String
containing a file
suffix (e.g., "image/jpeg" or "image/x-bmp").
Iterator
containing ImageWriter
s.
java.lang.IllegalArgumentException
- if MIMEType
is
null
.public static ImageWriter getImageWriter(ImageReader reader)
ImageWriter
corresponding to the given
ImageReader
, if there is one, or null
.
By obtaining this data from the ImageReader
and
passing it on to the ImageWriter
obtained with
this method, a client program can read an image, modify it
in some way, and write it back out, without having to understand
anything about the image format.
reader
- an instance of an ImageReader
.
ImageWriter
, or null.
java.lang.IllegalArgumentException
- if reader
is
null
.getImageReader(ImageWriter)
public static ImageReader getImageReader(ImageWriter writer)
ImageReader
corresponding to the given
ImageWriter
, if there is one, or null
.
This method is provided principally for symmetry with
getImageWriter(ImageReader)
.
writer
- an instance of an ImageWriter
.
ImageReader
, or null.
java.lang.IllegalArgumentException
- if writer
is
null
.getImageWriter(ImageReader)
public static java.util.Iterator getImageWriters(ImageTypeSpecifier type, java.lang.String formatName)
Iterator
containing all
ImageWriter
s that claim to be able to
encode images of the given layout (specified using an
ImageTypeSpecifier
) in the given format.
type
- an ImageTypeSpecifier
indicating the
layout of the image to be written.formatName
- the informal name of the format
.
Iterator
containing ImageWriter
s.
java.lang.IllegalArgumentException
- if any parameter is
null
.public static BufferedImage read(java.io.File input) throws java.io.IOException
BufferedImage
as the result of decoding
a supplied File
with an ImageReader
The File
is wrapped in an ImageInputStream
.
If no ImageReader
claims to be able to read 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 read
method that takes a
filename as a String
; use this method instead after
creating a File
from the filename.
input
- a File
to read from.
BufferedImage
containing the decoded
contents of the input, or null
.
java.lang.IllegalArgumentException
- if input
is
null
.
java.io.IOException
- if an error occurs during reading.public static BufferedImage read(java.io.InputStream input) throws java.io.IOException
BufferedImage
as the result of decoding
a supplied InputStream
with an ImageReader
.
The InputStream
is wrapped in an
ImageInputStream
. If no
ImageReader
claims to be able to read 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.
input
- an InputStream
to read from.
BufferedImage
containing the decoded
contents of the input, or null
.
java.lang.IllegalArgumentException
- if input
is
null
.
java.io.IOException
- if an error occurs during reading.public static BufferedImage read(java.net.URL input) throws java.io.IOException
BufferedImage
as the result of decoding
a supplied URL
with an ImageReader
An InputStream
is obtained from the URL
,
which is wrapped in an ImageInputStream
. If no
ImageReader
claims to be able to read
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.
input
- a URL
to read from.
BufferedImage
containing the decoded
contents of the input, or null
.
java.lang.IllegalArgumentException
- if input
is
null
.
java.io.IOException
- if an error occurs during reading.public static BufferedImage read(ImageInputStream stream) throws java.io.IOException
BufferedImage
as the result of decoding
a supplied ImageInputStream
with an
ImageReader
. If no ImageReader
claims
to be able to read the stream, null
is returned.
stream
- an ImageInputStream
to read from.
BufferedImage
containing the decoded
contents of the input, or null
.
java.lang.IllegalArgumentException
- if stream
is
null
.
java.io.IOException
- if an error occurs during reading.public static boolean write(RenderedImage im, java.lang.String formatName, ImageOutputStream output) throws java.io.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.
im
- a RenderedImage
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.
java.lang.IllegalArgumentException
- if any parameter is
null
.
java.lang.IllegalArgumentException
- if im
is not a
BufferedImage
. See restriction on RenderedImage
.
java.io.IOException
- if an error occurs during writing.public static boolean write(RenderedImage im, java.lang.String formatName, java.io.File output) throws java.io.IOException
ImageWriter
that supports the given format to a File
. If
there is already a File
present, its contents are
discarded.
im
- a RenderedImage
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.
java.lang.IllegalArgumentException
- if any parameter is
null
.
java.lang.IllegalArgumentException
- if im
is not a
BufferedImage
. See restriction on RenderedImage
.
java.io.IOException
- if an error occurs during writing.public static boolean write(RenderedImage im, java.lang.String formatName, java.io.OutputStream output) throws java.io.IOException
ImageWriter
that supports the given format to an OutputStream
.
The current cache settings from getUseCache
and
getCacheDirectory
will be used to control caching.
im
- a RenderedImage
to be written.formatName
- a String
containg the informal
name of the format.output
- an OutputStream
to be written to.
false
if no appropriate writer is found.
java.lang.IllegalArgumentException
- if any parameter is
null
.
java.lang.IllegalArgumentException
- if im
is not a
BufferedImage
. See restriction on RenderedImage
.
java.io.IOException
- if an error occurs during writing.
|
JSR-209 (Final Release) | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |