Class ImageReader

java.lang.Object
javax.imageio.ImageReader

public abstract class ImageReader extends Object
An abstract superclass for parsing and decoding of images. This class must be subclassed by classes that read in images in the context of the Java Image I/O framework.

ImageReader objects are normally instantiated by the service provider interface (SPI) class for the specific format. Service provider classes (e.g., instances of ImageReaderSpi) are registered with the IIORegistry, which uses them for format recognition and presentation of available format readers and writers.

When an input source is set (using the setInput method), it may be marked as "seek forward only". This setting means that images contained within the input source will only be read in order, possibly allowing the reader to avoid caching portions of the input containing data associated with images that have been read previously.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Locale[]
    An array of Locales which may be used to localize warning messages, or null if localization is not supported.
    protected boolean
    true if the current input source has been marked as allowing metadata to be ignored by setInput.
    protected Object
    The ImageInputStream or other Object by setInput and retrieved by getInput.
    protected Locale
    The current Locale to be used for localization, or null if none has been set.
    protected int
    The smallest valid index for reading, initially 0.
    protected ImageReaderSpi
    The ImageReaderSpi that instantiated this object, or null if its identity is not known or none exists.
    A List of currently registered IIOReadProgressListeners, initialized by default to null, which is synonymous with an empty List.
    protected boolean
    true if the current input source has been marked as allowing only forward seeking by setInput.
    A List of currently registered IIOReadUpdateListeners, initialized by default to null, which is synonymous with an empty List.
    A List of currently registered IIOReadWarningListeners, initialized by default to null, which is synonymous with an empty List.
    protected List<Locale>
    A List of the Locales associated with each currently registered IIOReadWarningListener, initialized by default to null, which is synonymous with an empty List.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ImageReader(ImageReaderSpi originatingProvider)
    Constructs an ImageReader and sets its originatingProvider field to the supplied value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Requests that any current read operation be aborted.
    protected boolean
    Returns true if a request to abort the current read operation has been made since the reader was instantiated or clearAbortRequest was called.
    void
    Adds an IIOReadProgressListener to the list of registered progress listeners.
    void
    Adds an IIOReadUpdateListener to the list of registered update listeners.
    void
    Adds an IIOReadWarningListener to the list of registered warning listeners.
    boolean
    Returns true if this plug-in supports reading just a Raster of pixel data.
    protected static void
    checkReadParamBandSettings(ImageReadParam param, int numSrcBands, int numDstBands)
    A utility method that may be used by readers to test the validity of the source and destination band settings of an ImageReadParam.
    protected void
    Clears any previous abort request.
    protected static void
    computeRegions(ImageReadParam param, int srcWidth, int srcHeight, BufferedImage image, Rectangle srcRegion, Rectangle destRegion)
    Computes the source region of interest and the destination region of interest, taking the width and height of the source image, an optional destination image, and an optional ImageReadParam into account.
    void
    Allows any resources held by this object to be released.
    float
    getAspectRatio(int imageIndex)
    Returns the aspect ratio of the given image (that is, its width divided by its height) as a float.
    Returns an array of Locales that may be used to localize warning listeners and compression settings.
    Returns a default ImageReadParam object appropriate for this format.
    protected static BufferedImage
    getDestination(ImageReadParam param, Iterator<ImageTypeSpecifier> imageTypes, int width, int height)
    Returns the BufferedImage to which decoded pixel data should be written.
    Returns a String identifying the format of the input source.
    abstract int
    getHeight(int imageIndex)
    Returns the height in pixels of the given image within the input source.
    abstract 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.
    getImageMetadata(int imageIndex, String formatName, Set<String> nodeNames)
    Returns an IIOMetadata object representing the metadata associated with the given image, or null if the reader does not support reading metadata or none is available.
    getImageTypes(int imageIndex)
    Returns an Iterator containing possible image types to which the given image may be decoded, in the form of ImageTypeSpecifierss.
    Returns the ImageInputStream or other Object previously set as the input source.
    Returns the currently set Locale, or null if none has been set.
    int
    Returns the lowest valid index for reading an image, thumbnail, or image metadata.
    abstract int
    getNumImages(boolean allowSearch)
    Returns the number of images, not including thumbnails, available from the current input source.
    int
    getNumThumbnails(int imageIndex)
    Returns the number of thumbnail preview images associated with the given image.
    Returns the ImageReaderSpi that was passed in on the constructor.
    getRawImageType(int imageIndex)
    Returns an ImageTypeSpecifier indicating the SampleModel and ColorModel which most closely represents the "raw" internal format of the image.
    protected static Rectangle
    getSourceRegion(ImageReadParam param, int srcWidth, int srcHeight)
    A utility method that may be used by readers to compute the region of the source image that should be read, taking into account any source region and subsampling offset settings in the supplied ImageReadParam.
    abstract IIOMetadata
    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.
    getStreamMetadata(String formatName, Set<String> nodeNames)
    Returns an IIOMetadata object representing the metadata associated with the input source as a whole (i.e., not associated with any particular image).
    int
    getThumbnailHeight(int imageIndex, int thumbnailIndex)
    Returns the height of the thumbnail preview image indexed by thumbnailIndex, associated with the image indexed by ImageIndex.
    int
    getThumbnailWidth(int imageIndex, int thumbnailIndex)
    Returns the width of the thumbnail preview image indexed by thumbnailIndex, associated with the image indexed by ImageIndex.
    int
    getTileGridXOffset(int imageIndex)
    Returns the X coordinate of the upper-left corner of tile (0, 0) in the given image.
    int
    getTileGridYOffset(int imageIndex)
    Returns the Y coordinate of the upper-left corner of tile (0, 0) in the given image.
    int
    getTileHeight(int imageIndex)
    Returns the height of a tile in the given image.
    int
    getTileWidth(int imageIndex)
    Returns the width of a tile in the given image.
    abstract int
    getWidth(int imageIndex)
    Returns the width in pixels of the given image within the input source.
    boolean
    hasThumbnails(int imageIndex)
    Returns true if the given image has thumbnail preview images associated with it.
    boolean
    Returns true if the current input source has been marked as allowing metadata to be ignored by passing true as the ignoreMetadata argument to the setInput method.
    boolean
    isImageTiled(int imageIndex)
    Returns true if the image is organized into tiles, that is, equal-sized non-overlapping rectangles.
    boolean
    isRandomAccessEasy(int imageIndex)
    Returns true if the storage format of the given image places no inherent impediment on random access to pixels.
    boolean
    Returns true if the current input source has been marked as seek forward only by passing true as the seekForwardOnly argument to the setInput method.
    protected void
    Broadcasts the completion of an image read to all registered IIOReadProgressListeners by calling their imageComplete method.
    protected void
    processImageProgress(float percentageDone)
    Broadcasts the current percentage of image completion to all registered IIOReadProgressListeners by calling their imageProgress method.
    protected void
    processImageStarted(int imageIndex)
    Broadcasts the start of an image read to all registered IIOReadProgressListeners by calling their imageStarted method.
    protected void
    processImageUpdate(BufferedImage theImage, int minX, int minY, int width, int height, int periodX, int periodY, int[] bands)
    Broadcasts the update of a set of samples to all registered IIOReadUpdateListeners by calling their imageUpdate method.
    protected void
    Broadcasts the end of a progressive pass to all registered IIOReadUpdateListeners by calling their passComplete method.
    protected void
    processPassStarted(BufferedImage theImage, int pass, int minPass, int maxPass, int minX, int minY, int periodX, int periodY, int[] bands)
    Broadcasts the beginning of a progressive pass to all registered IIOReadUpdateListeners by calling their passStarted method.
    protected void
    Broadcasts that the read has been aborted to all registered IIOReadProgressListeners by calling their readAborted method.
    protected void
    Broadcasts the completion of an sequence of image reads to all registered IIOReadProgressListeners by calling their sequenceComplete method.
    protected void
    processSequenceStarted(int minIndex)
    Broadcasts the start of an sequence of image reads to all registered IIOReadProgressListeners by calling their sequenceStarted method.
    protected void
    Broadcasts the completion of a thumbnail read to all registered IIOReadProgressListeners by calling their thumbnailComplete method.
    protected void
    Broadcasts the end of a thumbnail progressive pass to all registered IIOReadUpdateListeners by calling their thumbnailPassComplete method.
    protected void
    processThumbnailPassStarted(BufferedImage theThumbnail, int pass, int minPass, int maxPass, int minX, int minY, int periodX, int periodY, int[] bands)
    Broadcasts the beginning of a thumbnail progressive pass to all registered IIOReadUpdateListeners by calling their thumbnailPassStarted method.
    protected void
    processThumbnailProgress(float percentageDone)
    Broadcasts the current percentage of thumbnail completion to all registered IIOReadProgressListeners by calling their thumbnailProgress method.
    protected void
    processThumbnailStarted(int imageIndex, int thumbnailIndex)
    Broadcasts the start of a thumbnail read to all registered IIOReadProgressListeners by calling their thumbnailStarted method.
    protected void
    processThumbnailUpdate(BufferedImage theThumbnail, int minX, int minY, int width, int height, int periodX, int periodY, int[] bands)
    Broadcasts the update of a set of samples in a thumbnail image to all registered IIOReadUpdateListeners by calling their thumbnailUpdate method.
    protected void
    Broadcasts a warning message to all registered IIOReadWarningListeners by calling their warningOccurred method.
    protected void
    processWarningOccurred(String baseName, String keyword)
    Broadcasts a localized warning message to all registered IIOReadWarningListeners by calling their warningOccurred method with a string taken from a ResourceBundle.
    read(int imageIndex)
    Reads the image indexed by imageIndex and returns it as a complete BufferedImage, using a default ImageReadParam.
    abstract BufferedImage
    read(int imageIndex, ImageReadParam param)
    Reads the image indexed by imageIndex and returns it as a complete BufferedImage, using a supplied ImageReadParam.
    readAll(int imageIndex, ImageReadParam param)
    Reads the image indexed by imageIndex and returns an IIOImage containing the image, thumbnails, and associated image metadata, using a supplied ImageReadParam.
    readAll(Iterator<? extends ImageReadParam> params)
    Returns an Iterator containing all the images, thumbnails, and metadata, starting at the index given by getMinIndex, from the input source in the form of IIOImage objects.
    readAsRenderedImage(int imageIndex, ImageReadParam param)
    Returns a RenderedImage object that contains the contents of the image indexed by imageIndex.
    boolean
    Returns true if the image format understood by this reader supports thumbnail preview images associated with it.
    readRaster(int imageIndex, ImageReadParam param)
    Returns a new Raster object containing the raw pixel data from the image stream, without any color conversion applied.
    readThumbnail(int imageIndex, int thumbnailIndex)
    Returns the thumbnail preview image indexed by thumbnailIndex, associated with the image indexed by ImageIndex as a BufferedImage.
    readTile(int imageIndex, int tileX, int tileY)
    Reads the tile indicated by the tileX and tileY arguments, returning it as a BufferedImage.
    readTileRaster(int imageIndex, int tileX, int tileY)
    Returns a new Raster object containing the raw pixel data from the tile, without any color conversion applied.
    void
    Removes all currently registered IIOReadProgressListener objects.
    void
    Removes all currently registered IIOReadUpdateListener objects.
    void
    Removes all currently registered IIOReadWarningListener objects.
    void
    Removes an IIOReadProgressListener from the list of registered progress listeners.
    void
    Removes an IIOReadUpdateListener from the list of registered update listeners.
    void
    Removes an IIOReadWarningListener from the list of registered error listeners.
    void
    Restores the ImageReader to its initial state.
    void
    Sets the input source to use to the given ImageInputStream or other Object.
    void