📄 imagereader.java
字号:
{ boolean classOk = false; for (int i = 0; i < okClasses.length; ++i) if (okClasses[i].isInstance(input)) classOk = true; if (!classOk) throw new IllegalArgumentException(); } this.input = input; this.seekForwardOnly = seekForwardOnly; this.ignoreMetadata = ignoreMetadata; this.minIndex = 0; } /** * Set the input source to the given object and specify whether this * reader should be allowed to read input from the data stream more * than once. The input source must be set before many methods can * be called on this reader. (see all ImageReader methods that throw * IllegalStateException). If input is null then the current input * source will be removed. * * @param input the input source object * @param seekForwardOnly true if this reader should be allowed to * read input from the data stream more than once, false otherwise * * @exception IllegalArgumentException if input is not a valid input * source for this reader and is not an ImageInputStream */ public void setInput(Object in, boolean seekForwardOnly) { setInput(in, seekForwardOnly, false); } /** * Set the input source to the given object. The input source must * be set before many methods can be called on this reader. (see all * ImageReader methods that throw IllegalStateException). If input * is null then the current input source will be removed. * * @param input the input source object * * @exception IllegalArgumentException if input is not a valid input * source for this reader and is not an ImageInputStream */ public void setInput(Object input) { setInput(input, false, false); } /** * Get this reader's image input source. null is returned if the * image source has not been set. * * @return an image input source object, or null */ public Object getInput() { return input; } /** * Get this reader's locale. null is returned if the locale has not * been set. * * @return this reader's locale, or null */ public Locale getLocale() { return locale; } /** * Return the number of images available from the image input * source, not including thumbnails. This method will return 1 * unless this reader is reading an animated image. * * Certain multi-image formats do not encode the total number of * images. When reading images in those formats it may be necessary * to repeatedly call read, incrementing the image index at each * call, until an IndexOutOfBoundsException is thrown. * * The allowSearch parameter determines whether all images must be * available at all times. When allowSearch is false, getNumImages * will return -1 if the total number of images is unknown. * Otherwise this method returns the number of images. * * @param allowSearch true if all images should be available at * once, false otherwise * * @return -1 if allowSearch is false and the total number of images * is currently unknown, or the number of images * * @exception IllegalStateException if input has not been set, or if * seekForwardOnly is true * @exception IOException if a read error occurs */ public abstract int getNumImages(boolean allowSearch) throws IOException; /** * Get the number of thumbnails associated with an image. * * @param imageIndex the frame index * * @return the number of thumbnails associated with this image */ public int getNumThumbnails(int imageIndex) throws IOException { return 0; } /** * Get the ImageReaderSpi that created this reader or null. * * @return an ImageReaderSpi, or null */ public ImageReaderSpi getOriginatingProvider() { return originatingProvider; } /** * Get the metadata associated with the image being read. If the * reader is set to ignore metadata or does not support reading * metadata, or if no metadata is available then null is returned. * This method returns metadata associated with the entirety of the * image data, whereas getImageMetadata(int) returns metadata * associated with a frame within a multi-image data stream. * * @return metadata associated with the image being read, or null * * @exception IOException if a read error occurs */ public abstract IIOMetadata getStreamMetadata() throws IOException; /** * Get the height of a thumbnail image. * * @param imageIndex the frame index * @param thumbnailIndex the thumbnail index * * @return the height of the thumbnail image * * @exception UnsupportedOperationException if this reader does not * support thumbnails * @exception IllegalStateException if input is null * @exception IndexOutOfBoundsException if either index is * out-of-bounds * @exception IOException if a read error occurs */ public int getThumbnailHeight(int imageIndex, int thumbnailIndex) throws IOException { return readThumbnail(imageIndex, thumbnailIndex).getHeight(); } /** * Get the width of a thumbnail image. * * @param imageIndex the frame index * @param thumbnailIndex the thumbnail index * * @return the width of the thumbnail image * * @exception UnsupportedOperationException if this reader does not * support thumbnails * @exception IllegalStateException if input is null * @exception IndexOutOfBoundsException if either index is * out-of-bounds * @exception IOException if a read error occurs */ public int getThumbnailWidth(int imageIndex, int thumbnailIndex) throws IOException { return readThumbnail(imageIndex, thumbnailIndex).getWidth(); } /** * Get the X coordinate in pixels of the top-left corner of the * first tile in this image. * * @param imageIndex the frame index * * @return the X coordinate of this image's first tile * * @exception IllegalStateException if input is needed but the input * source is not set * @exception IndexOutOfBoundsException if the frame index is * out-of-bounds * @exception IOException if a read error occurs */ public int getTileGridXOffset(int imageIndex) throws IOException { return 0; } /** * Get the Y coordinate in pixels of the top-left corner of the * first tile in this image. * * @param imageIndex the frame index * * @return the Y coordinate of this image's first tile * * @exception IllegalStateException if input is needed but the input * source is not set * @exception IndexOutOfBoundsException if the frame index is * out-of-bounds * @exception IOException if a read error occurs */ public int getTileGridYOffset(int imageIndex) throws IOException { return 0; } /** * Get the height of an image tile. * * @param imageIndex the frame index * * @return the tile height for the given image * * @exception IllegalStateException if input is null * @exception IndexOutOfBoundsException if the frame index is * out-of-bounds * @exception IOException if a read error occurs */ public int getTileHeight(int imageIndex) throws IOException { return getHeight(imageIndex); } /** * Get the width of an image tile. * * @param imageIndex the frame index * * @return the tile width for the given image * * @exception IllegalStateException if input is null * @exception IndexOutOfBoundsException if the frame index is * out-of-bounds * @exception IOException if a read error occurs */ public int getTileWidth(int imageIndex) throws IOException { return getWidth(imageIndex); } /** * Get the width of the input image in pixels. If the input image * is resizable then a default width is returned. * * @param imageIndex the image's index * * @return the width of the input image * * @exception IllegalStateException if input has not been set * @exception IndexOutOfBoundsException if the frame index is * out-of-bounds * @exception IOException if a read error occurs */ public abstract int getWidth(int imageIndex) throws IOException; /** * Check whether or not the given image has thumbnails associated * with it. * * @return true if the given image has thumbnails, false otherwise * * @exception IllegalStateException if input is null * @exception IndexOutOfBoundsException if the frame index is * out-of-bounds * @exception IOException if a read error occurs */ public boolean hasThumbnails(int imageIndex) throws IOException { return getNumThumbnails(imageIndex) > 0; } /** * Check if this image reader ignores metadata. This method simply * returns the value of ignoreMetadata. * * @return true if metadata is being ignored, false otherwise */ public boolean isIgnoringMetadata() { return ignoreMetadata; } /** * Check if the given image is sub-divided into equal-sized * non-overlapping pixel rectangles. * * A reader may expose tiling in the underlying format, hide it, or * simulate tiling even if the underlying format is not tiled. * * @return true if the given image is tiled, false otherwise * * @exception IllegalStateException if input is null * @exception IndexOutOfBoundsException if the frame index is * out-of-bounds * @exception IOException if a read error occurs */ public boolean isImageTiled(int imageIndex) throws IOException { return false; } /** * Check if all pixels in this image are readily accessible. This * method should return false for compressed formats. The return * value is a hint as to the efficiency of certain image reader * operations. * * @param imageIndex the frame index * * @return true if random pixel access is fast, false otherwise * * @exception IllegalStateException if input is null and it is * needed to determine the return value * @exception IndexOutOfBoundsException if the frame index is * out-of-bounds but the frame data must be accessed to determine * the return value * @exception IOException if a read error occurs */ public boolean isRandomAccessEasy(int imageIndex) throws IOException { return false; } /** * Check if this image reader may only seek forward within the input * stream. * * @return true if this reader may only seek forward, false * otherwise */ public boolean isSeekForwardOnly() { return seekForwardOnly; } /** * Notifies all installed read progress listeners that image loading * has completed by calling their imageComplete methods. */ protected void processImageComplete() { if (progressListeners != null) { Iterator it = progressListeners.iterator(); while (it.hasNext()) { IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); listener.imageComplete (this); } } } /** * Notifies all installed read progress listeners that a certain * percentage of the image has been loaded, by calling their * imageProgress methods. * * @param percentageDone the percentage of image data that has been * loaded */ protected void processImageProgress(float percentageDone) { if (progressListeners != null) { Iterator it = progressListeners.iterator(); while (it.hasNext()) { IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); listener.imageProgress(this, percentageDone); } } } /** * Notifies all installed read progress listeners, by calling their * imageStarted methods, that image loading has started on the given * image. * * @param imageIndex the frame index of the image that has started * loading */ protected void processImageStarted(int imageIndex) { if (progressListeners != null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -