📄 imagereader.java
字号:
} /** * Read the given frame into a buffered image using the given read * parameters. Listeners will be notified of image loading progress * and warnings. * * @param imageIndex the index of the frame to read * @param param the image read parameters to use when reading * * @return a buffered 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 abstract BufferedImage read(int imageIndex, ImageReadParam param) throws IOException; /** * Check if this reader supports reading thumbnails. * * @return true if this reader supports reading thumbnails, false * otherwise */ public boolean readerSupportsThumbnails() { return false; } /** * Read raw raster data. The image type specifier in param is * ignored but all other parameters are used. Offset parameters are * translated into the raster's coordinate space. This method may * be implemented by image readers that want to provide direct * access to raw image data. * * @param imageIndex the frame index * @param param the image read parameters * * @return a raster containing the read image data * * @exception UnsupportedOperationException if this reader doesn't * support rasters * @exception IllegalStateException if input is null * @exception IndexOutOfBoundsException if the frame index is * out-of-bounds * @exception IOException if a read error occurs */ public Raster readRaster(int imageIndex, ImageReadParam param) throws IOException { throw new UnsupportedOperationException(); } /** * Read a thumbnail. * * @param imageIndex the frame index * @param thumbnailIndex the thumbnail index * * @return a buffered image of the thumbnail * * @exception UnsupportedOperationException if this reader doesn't * support thumbnails * @exception IllegalStateException if input is null * @exception IndexOutOfBoundsException if either the frame index or * the thumbnail index is out-of-bounds * @exception IOException if a read error occurs * */ public BufferedImage readThumbnail(int imageIndex, int thumbnailIndex) throws IOException { throw new UnsupportedOperationException(); } /** * Uninstall all read progress listeners. */ public void removeAllIIOReadProgressListeners() { progressListeners = null; } /** * Uninstall all read update listeners. */ public void removeAllIIOReadUpdateListeners() { updateListeners = null; } /** * Uninstall all read warning listeners. */ public void removeAllIIOReadWarningListeners() { warningListeners = null; } /** * Uninstall the given read progress listener. * * @param listener the listener to remove */ public void removeIIOReadProgressListener(IIOReadProgressListener listener) { if (listener == null) return; if (progressListeners != null) { progressListeners.remove(listener); } } /** * Uninstall the given read update listener. * * @param listener the listener to remove */ public void removeIIOReadUpdateListener(IIOReadUpdateListener listener) { if (listener == null) return; if (updateListeners != null) { updateListeners.remove(listener); } } /** * Uninstall the given read warning listener. * * @param listener the listener to remove */ public void removeIIOReadWarningListener(IIOReadWarningListener listener) { if (listener == null) return; if (warningListeners != null) { warningListeners.remove(listener); } } /** * Set the current locale or use the default locale. * * @param locale the locale to set, or null */ public void setLocale(Locale locale) { if (locale != null) { // Check if its a valid locale. boolean found = false; if (availableLocales != null) for (int i = availableLocales.length - 1; i >= 0; --i) if (availableLocales[i].equals(locale)) found = true; if (! found) throw new IllegalArgumentException("looale not available"); } this.locale = locale; } /** * Check that the given read parameters have valid source and * destination band settings. If the param.getSourceBands() returns * null, the array is assumed to include all band indices, 0 to * numSrcBands - 1; likewise if param.getDestinationBands() returns * null, it is assumed to be an array containing indices 0 to * numDstBands - 1. A failure will cause this method to throw * IllegalArgumentException. * * @param param the image parameters to check * @param numSrcBands the number of input source bands * @param numDstBands the number of ouput destination bands * * @exception IllegalArgumentException if either the given source or * destination band indices are invalid */ protected static void checkReadParamBandSettings(ImageReadParam param, int numSrcBands, int numDstBands) { int[] srcBands = param.getSourceBands(); int[] dstBands = param.getDestinationBands(); boolean lengthsDiffer = false; boolean srcOOB = false; boolean dstOOB = false; if (srcBands == null) { if (dstBands == null) { if (numSrcBands != numDstBands) lengthsDiffer = true; } else { if (numSrcBands != dstBands.length) lengthsDiffer = true; for (int i = 0; i < dstBands.length; i++) if (dstBands[i] > numSrcBands - 1) { dstOOB = true; break; } } } else { if (dstBands == null) { if (srcBands.length != numDstBands) lengthsDiffer = true; for (int i = 0; i < srcBands.length; i++) if (srcBands[i] > numDstBands - 1) { srcOOB = true; break; } } else { if (srcBands.length != dstBands.length) lengthsDiffer = true; for (int i = 0; i < srcBands.length; i++) if (srcBands[i] > numDstBands - 1) { srcOOB = true; break; } for (int i = 0; i < dstBands.length; i++) if (dstBands[i] > numSrcBands - 1) { dstOOB = true; break; } } } if (lengthsDiffer) throw new IllegalArgumentException ("array lengths differ"); if (srcOOB) throw new IllegalArgumentException ("source band index" + " out-of-bounds"); if (dstOOB) throw new IllegalArgumentException ("destination band index" + " out-of-bounds"); } /** * Calcluate the source and destination regions that will be read * from and written to, given image parameters and/or a destination * buffered image. The source region will be clipped if any of its * bounds are outside the destination region. Clipping will account * for subsampling and destination offsets. Likewise, the * destination region is clipped to the given destination image, if * it is not null, using the given image parameters, if they are not * null. IllegalArgumentException is thrown if either region will * contain 0 pixels after clipping. * * @param image read parameters, or null * @param srcWidth the width of the source image * @param srcHeight the height of the source image * @param image the destination image, or null * @param srcRegion a rectangle whose values will be set to the * clipped source region * @param destRegion a rectangle whose values will be set to the * clipped destination region * * @exception IllegalArgumentException if either srcRegion or * destRegion is null * @exception IllegalArgumentException if either of the calculated * regions is empty */ protected static void computeRegions (ImageReadParam param, int srcWidth, int srcHeight, BufferedImage image, Rectangle srcRegion, Rectangle destRegion) { if (srcRegion == null || destRegion == null) throw new IllegalArgumentException ("null region"); if (srcWidth == 0 || srcHeight == 0) throw new IllegalArgumentException ("zero-sized region"); srcRegion = getSourceRegion(param, srcWidth, srcHeight); if (image != null) destRegion = new Rectangle (0, 0, image.getWidth(), image.getHeight()); else destRegion = new Rectangle (0, 0, srcWidth, srcHeight); if (param != null) { Point offset = param.getDestinationOffset(); if (offset.x < 0) { srcRegion.x -= offset.x; srcRegion.width += offset.x; } if (offset.y < 0) { srcRegion.y -= offset.y; srcRegion.height += offset.y; } srcRegion.width = srcRegion.width > destRegion.width ? destRegion.width : srcRegion.width; srcRegion.height = srcRegion.height > destRegion.height ? destRegion.height : srcRegion.height; if (offset.x >= 0) { destRegion.x += offset.x; destRegion.width -= offset.x; } if (offset.y >= 0) { destRegion.y += offset.y; destRegion.height -= offset.y; } } if (srcRegion.isEmpty() || destRegion.isEmpty()) throw new IllegalArgumentException ("zero-sized region"); } /** * Return a suitable destination buffered image. If * param.getDestination() is non-null, then it is returned, * otherwise a buffered image is created using * param.getDestinationType() if it is non-null and also in the * given imageTypes collection, or the first element of imageTypes * otherwise. * * @param param image read parameters from which a destination image * or image type is retrieved, or null * @param imageTypes a collection of legal image types * @param width the width of the source image * @param height the height of the source image * * @return a suitable destination buffered image * * @exception IIOException if param.getDestinationType() does not * return an image type in imageTypes * @exception IllegalArgumentException if imageTypes is null or * empty, or if a non-ImageTypeSpecifier object is retrieved from * imageTypes * @exception IllegalArgumentException if the resulting destination * region is empty * @exception IllegalArgumentException if the product of width and * height is greater than Integer.MAX_VALUE */ protected static BufferedImage getDestination (ImageReadParam param, Iterator imageTypes, int width, int height) throws IIOException { if (imageTypes == null || !imageTypes.hasNext()) throw new IllegalArgumentException ("imageTypes null or empty"); if (width < 0 || height < 0) throw new IllegalArgumentException ("negative dimension"); // test for overflow if (width * height < Math.min (width, height)) throw new IllegalArgumentException ("width * height > Integer.MAX_VALUE"); BufferedImage dest = null; ImageTypeSpecifier destType = null; if (param != null) { dest = param.getDestination (); if (dest == null) { ImageTypeSpecifier type = param.getDestinationType(); if (type != null) { Iterator it = imageTypes; while (it.hasNext()) { Object o = it.next (); if (! (o instanceof ImageTypeSpecifier)) throw new IllegalArgumentException ("non-ImageTypeSpecifier object"); ImageTypeSpecifier t = (ImageTypeSpecifier) o; if (t.equals (type))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -