public class

BMPImageReader

extends ImageReader
implements BMPConstants
java.lang.Object
   ↳ javax.imageio.ImageReader
     ↳ com.sun.imageio.plugins.bmp.BMPImageReader

Class Overview

This class is the Java Image IO plugin reader for BMP images. It may subsample the image, clip the image, select sub-bands, and shift the decoded image origin if the proper decoding parameter are set in the provided ImageReadParam. This class supports Microsoft Windows Bitmap Version 3-5, as well as OS/2 Bitmap Version 2.x (for single-image BMP file).

Summary

[Expand]
Inherited Constants
From interface com.sun.imageio.plugins.bmp.BMPConstants
[Expand]
Inherited Fields
From class javax.imageio.ImageReader
From interface com.sun.imageio.plugins.bmp.BMPConstants
Public Constructors
BMPImageReader(ImageReaderSpi originator)
Constructs BMPImageReader from the provided ImageReaderSpi.
Public Methods
boolean canReadRaster()
Returns true if this plug-in supports reading just a Raster of pixel data.
ImageReadParam getDefaultReadParam()
Returns a default ImageReadParam object appropriate for this format.
int getHeight(int imageIndex)
Returns the height in pixels of the given image within the input source.
IIOMetadata getImageMetadata(int imageIndex)
Returns an IIOMetadata object containing metadata associated with the given image, or null if the reader does not support reading metadata, is set to ignore metadata, or if no metadata is available.
Iterator getImageTypes(int imageIndex)
Returns an Iterator containing possible image types to which the given image may be decoded, in the form of ImageTypeSpecifierss.
int getNumImages(boolean allowSearch)
Overrides the method defined in the superclass.
IIOMetadata getStreamMetadata()
Returns an IIOMetadata object representing the metadata associated with the input source as a whole (i.e., not associated with any particular image), or null if the reader does not support reading metadata, is set to ignore metadata, or if no metadata is available.
int getWidth(int imageIndex)
Returns the width in pixels of the given image within the input source.
boolean isRandomAccessEasy(int imageIndex)
Returns true if the storage format of the given image places no inherent impediment on random access to pixels.
BufferedImage read(int imageIndex, ImageReadParam param)
Reads the image indexed by imageIndex and returns it as a complete BufferedImage, using a supplied ImageReadParam.
void readHeader()
Raster readRaster(int imageIndex, ImageReadParam param)
Returns a new Raster object containing the raw pixel data from the image stream, without any color conversion applied.
void reset()
Restores the ImageReader to its initial state.
void setInput(Object input, boolean seekForwardOnly, boolean ignoreMetadata)
Overrides the method defined in the superclass.
[Expand]
Inherited Methods
From class javax.imageio.ImageReader
From class java.lang.Object

Public Constructors

public BMPImageReader (ImageReaderSpi originator)

Constructs BMPImageReader from the provided ImageReaderSpi.

Public Methods

public boolean canReadRaster ()

Returns true if this plug-in supports reading just a Raster of pixel data. If this method returns false, calls to readRaster or readTileRaster will throw an UnsupportedOperationException.

The default implementation returns false.

Returns
  • true if this plug-in supports reading raw Rasters.

public ImageReadParam getDefaultReadParam ()

Returns a default ImageReadParam object appropriate for this format. All subclasses should define a set of default values for all parameters and return them with this call. This method may be called before the input source is set.

The default implementation constructs and returns a new ImageReadParam object that does not allow source scaling (i.e., it returns new ImageReadParam().

Returns
  • an ImageReadParam object which may be used to control the decoding process using a set of default settings.

public int getHeight (int imageIndex)

Returns the height in pixels of the given image within the input source.

If the image can be rendered to a user-specified size, then this method returns the default height.

Parameters
imageIndex the index of the image to be queried.
Returns
  • the height of the image, as an int.
Throws
IOException

public IIOMetadata getImageMetadata (int imageIndex)

Returns an IIOMetadata object containing metadata associated with the given image, or null if the reader does not support reading metadata, is set to ignore metadata, or if no metadata is available.

Parameters
imageIndex the index of the image whose metadata is to be retrieved.
Returns
  • an IIOMetadata object, or null.
Throws
IOException

public Iterator getImageTypes (int imageIndex)

Returns an Iterator containing possible image types to which the given image may be decoded, in the form of ImageTypeSpecifierss. At least one legal image type will be returned.

The first element of the iterator should be the most "natural" type for decoding the image with as little loss as possible. For example, for a JPEG image the first entry should be an RGB image, even though the image data is stored internally in a YCbCr color space.

Parameters
imageIndex the index of the image to be retrieved.
Returns
  • an Iterator containing at least one ImageTypeSpecifier representing suggested image types for decoding the current given image.
Throws
IOException

public int getNumImages (boolean allowSearch)

Overrides the method defined in the superclass.

Parameters
allowSearch if true, the true number of images will be returned even if a search is required. If false, the reader may return -1 without performing the search.
Returns
  • the number of images, as an int, or -1 if allowSearch is false and a search would be required.
Throws
IOException

public IIOMetadata getStreamMetadata ()

Returns an IIOMetadata object representing the metadata associated with the input source as a whole (i.e., not associated with any particular image), or null if the reader does not support reading metadata, is set to ignore metadata, or if no metadata is available.

Returns
  • an IIOMetadata object, or null.
Throws
IOException

public int getWidth (int imageIndex)

Returns the width in pixels of the given image within the input source.

If the image can be rendered to a user-specified size, then this method returns the default width.

Parameters
imageIndex the index of the image to be queried.
Returns
  • the width of the image, as an int.
Throws
IOException

public boolean isRandomAccessEasy (int imageIndex)

Returns true if the storage format of the given image places no inherent impediment on random access to pixels. For most compressed formats, such as JPEG, this method should return false, as a large section of the image in addition to the region of interest may need to be decoded.

This is merely a hint for programs that wish to be efficient; all readers must be able to read arbitrary regions as specified in an ImageReadParam.

Note that formats that return false from this method may nonetheless allow tiling (e.g. Restart Markers in JPEG), and random access will likely be reasonably efficient on tiles. See isImageTiled.

A reader for which all images are guaranteed to support easy random access, or are guaranteed not to support easy random access, may return true or false respectively without accessing any image data. In such cases, it is not necessary to throw an exception even if no input source has been set or the image index is out of bounds.

The default implementation returns false.

Parameters
imageIndex the index of the image to be queried.
Returns
  • true if reading a region of interest of the given image is likely to be efficient.
Throws
IOException

public BufferedImage read (int imageIndex, ImageReadParam param)

Reads the image indexed by imageIndex and returns it as a complete BufferedImage, using a supplied ImageReadParam.

The actual BufferedImage returned will be chosen using the algorithm defined by the getDestination method.

Any registered IIOReadProgressListener objects will be notified by calling their imageStarted method, followed by calls to their imageProgress method as the read progresses. Finally their imageComplete method will be called. IIOReadUpdateListener objects may be updated at other times during the read as pixels are decoded. Finally, IIOReadWarningListener objects will receive notification of any non-fatal warnings that occur during decoding.

The set of source bands to be read and destination bands to be written is determined by calling getSourceBands and getDestinationBands on the supplied ImageReadParam. If the lengths of the arrays returned by these methods differ, the set of source bands contains an index larger that the largest available source index, or the set of destination bands contains an index larger than the largest legal destination index, an IllegalArgumentException is thrown.

If the supplied ImageReadParam contains optional setting values not supported by this reader (e.g. source render size or any format-specific settings), they will be ignored.

Parameters
imageIndex the index of the image to be retrieved.
param an ImageReadParam used to control the reading process, or null.
Returns
  • the desired portion of the image as a BufferedImage.
Throws
IOException

public void readHeader ()

Throws
IOException

public Raster readRaster (int imageIndex, ImageReadParam param)

Returns a new Raster object containing the raw pixel data from the image stream, without any color conversion applied. The application must determine how to interpret the pixel data by other means. Any destination or image-type parameters in the supplied ImageReadParam object are ignored, but all other parameters are used exactly as in the read method, except that any destination offset is used as a logical rather than a physical offset. The size of the returned Raster will always be that of the source region clipped to the actual image. Logical offsets in the stream itself are ignored.

This method allows formats that normally apply a color conversion, such as JPEG, and formats that do not normally have an associated colorspace, such as remote sensing or medical imaging data, to provide access to raw pixel data.

Any registered readUpdateListeners are ignored, as there is no BufferedImage, but all other listeners are called exactly as they are for the read method.

If canReadRaster() returns false, this method throws an UnsupportedOperationException.

If the supplied ImageReadParam contains optional setting values not supported by this reader (e.g. source render size or any format-specific settings), they will be ignored.

The default implementation throws an UnsupportedOperationException.

Parameters
imageIndex the index of the image to be read.
param an ImageReadParam used to control the reading process, or null.
Returns
  • the desired portion of the image as a Raster.
Throws
IOException

public void reset ()

Restores the ImageReader to its initial state.

The default implementation calls setInput(null, false), setLocale(null), removeAllIIOReadUpdateListeners(), removeAllIIOReadWarningListeners(), removeAllIIOReadProgressListeners(), and clearAbortRequest.

public void setInput (Object input, boolean seekForwardOnly, boolean ignoreMetadata)

Overrides the method defined in the superclass.

Parameters
input the ImageInputStream or other Object to use for future decoding.
seekForwardOnly if true, images and metadata may only be read in ascending order from this input source.
ignoreMetadata if true, metadata may be ignored during reads.