Javatpoint Logo
Javatpoint Logo

Java ImageIO Class

The Java ImageIO class is a final class that belongs to javax.imageio package. The class provides the convenience method for reading and writing image and perfuming simple encoding and decoding. The class provides a lot of utility methods related to image processing. Using the class, we can deal with the popular image extensions like, .jpg, .bmp, .gif, .png, etc. In this section, we will also discuss how to read and write an image using Java ImageIO class.

Java ImageIO Class Methods

Method Description
createImageInputStream(Object input) Returns an ImageInputStream that will take its input from the given Object.
createImageOutputStream(Object output) Returns an ImageOutputStream that will send its output to the given Object.
getCacheDirectory() Returns the current value set by setCacheDirectory, or null if no explicit setting has been made.
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.
getImageReaders(Object input) Returns an Iterator containing all currently registered ImageReaders that claim to be able to decode the supplied Object, typically an ImageInputStream.
getImageReadersByFormatName(String formatName) Returns an Iterator containing all currently registered ImageReaders that claim to be able to decode the named format.
getImageReadersByMIMEType(String MIMEType) Returns an Iterator containing all currently registered ImageReaders that claim to be able to decode files with the given MIME type.
getImageReadersBySuffix(String fileSuffix) Returns an Iterator containing all currently registered ImageReaders that claim to be able to decode files with the given suffix.
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.
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.
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.
getImageWritersByFormatName(String formatName) Returns an Iterator containing all currently registered ImageWriters that claim to be able to encode the named format.
getImageWritersByMIMEType(String MIMEType) Returns an Iterator containing all currently registered ImageWriters that claim to be able to encode files with the given MIME type.
getImageWritersBySuffix(String fileSuffix) Returns an Iterator containing all currently registered ImageWriters that claim to be able to encode files with the given suffix.
getReaderFileSuffixes() Returns an array of Strings listing all of the file suffixes associated with the formats understood by the current set of registered readers.
getReaderFormatNames() Returns an array of Strings listing all of the informal format names understood by the current set of registered readers.
getReaderMIMETypes() Returns an array of Strings listing all of the MIME types understood by the current set of registered readers.
getUseCache() Returns the current value set by setUseCache, or true if no explicit setting has been made.
getWriterFileSuffixes() Returns an array of Strings listing all of the file suffixes associated with the formats understood by the current set of registered writers.
getWriterFormatNames() Returns an array of Strings listing all of the informal format names understood by the current set of registered writers.
getWriterMIMETypes() Returns an array of Strings listing all of the MIME types understood by the current set of registered writers.
read(File input) Returns a BufferedImage as the result of decoding a supplied File with an ImageReader chosen automatically from among those currently registered.
read(ImageInputStream stream) Returns a BufferedImage as the result of decoding a supplied ImageInputStream with an ImageReader chosen automatically from among those currently registered.
read(InputStream input) Returns a BufferedImage as the result of decoding a supplied InputStream with an ImageReader chosen automatically from among those currently registered.
read(URL input) Returns a BufferedImage as the result of decoding a supplied URL with an ImageReader chosen automatically from among those currently registered.
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.
setCacheDirectory(File cacheDirectory) Sets the directory where cache files are to be created.
setUseCache(boolean useCache) Sets a flag indicating whether a disk-based cache file should be used when creating ImageInputStreams and ImageOutputStreams.
write(RenderedImage im, String formatName, File output) Writes an image using an arbitrary ImageWriter that supports the given format to a File.
write(RenderedImage im, String formatName, ImageOutputStream output) Writes an image using an arbitrary ImageWriter that supports the given format to an ImageOutputStream.
write(RenderedImage im, String formatName, OutputStream output) Writes an image using an arbitrary ImageWriter that supports the given format to an OutputStream.

Image Read Write Example

ImageIOExample.java

Output:

Success

The program reads and writes the image with the extension that we have specified.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA