📄 imagewriter.java
字号:
* Retrieve the default write parameters for this writer's image * format. * * The default implementation returns new ImageWriteParam(). * * @return image writing parameters */ public ImageWriteParam getDefaultWriteParam() { return new ImageWriteParam(getLocale()); } /** * Get this writer's locale. null is returned if the locale has not * been set. * * @return this writer's locale, or null */ public Locale getLocale() { return locale; } /** * Get the number of thumbnails supported by this image writer, * based on the given image type, image writing parameters, and * stream and image metadata. The image writing parameters are * optional, in case they affect the number of thumbnails supported. * * @param imageType an image type specifier, or null * @param param image writing parameters, or null * @param streamMetadata the metadata associated with this stream, * or null * @param imageMetadata the metadata associated with this image, or * null * * @return the number of thumbnails that this writer supports * writing or -1 if the given information is insufficient */ public int getNumThumbnailsSupported (ImageTypeSpecifier imageType, ImageWriteParam param, IIOMetadata streamMetadata, IIOMetadata imageMetadata) { return 0; } /** * Get the ImageWriterSpi that created this writer or null. * * @return an ImageWriterSpi, or null */ public ImageWriterSpi getOriginatingProvider() { return originatingProvider; } /** * Get this reader's image output destination. null is returned if * the image destination has not been set. * * @return an image output destination object, or null */ public Object getOutput() { return output; } /** * Get the preferred sizes for thumbnails based on the given image * type, image writing parameters, and stream and image metadata. * The preferred sizes are returned in pairs of dimension values; * the first value in the array is a dimension object representing * the minimum thumbnail size, the second value is a dimension * object representing a maximum thumbnail size. The writer can * select a size within the range given by each pair, or it can * ignore these size hints. * * @param imageType an image type specifier, or null * @param param image writing parameters, or null * @param streamMetadata the metadata associated with this stream, * or null * @param imageMetadata the metadata associated with this image, or * null * * @return an array of dimension pairs whose length is a multiple of * 2, or null if there is no preferred size (any size is allowed) or * if the size is unknown (insufficient information was provided) */ public Dimension[] getPreferredThumbnailSizes (ImageTypeSpecifier imageType, ImageWriteParam param, IIOMetadata streamMetadata, IIOMetadata imageMetadata) { return null; } /** * Notifies all installed write 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()) { IIOWriteProgressListener listener = (IIOWriteProgressListener) it.next(); listener.imageComplete(this); } } } /** * Notifies all installed write 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()) { IIOWriteProgressListener listener = (IIOWriteProgressListener) it.next(); listener.imageProgress(this, percentageDone); } } } /** * Notifies all installed write 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) { Iterator it = progressListeners.iterator(); while (it.hasNext()) { IIOWriteProgressListener listener = (IIOWriteProgressListener) it.next(); listener.imageStarted(this, imageIndex); } } } /** * Notifies all installed write progress listeners, by calling their * thumbnailComplete methods, that a thumbnail has completed * loading. */ protected void processThumbnailComplete() { if (progressListeners != null) { Iterator it = progressListeners.iterator(); while (it.hasNext()) { IIOWriteProgressListener listener = (IIOWriteProgressListener) it.next(); listener.thumbnailComplete(this); } } } /** * Notifies all installed write progress listeners that a certain * percentage of a thumbnail has been loaded, by calling their * thumbnailProgress methods. * * @param percentageDone the percentage of thumbnail data that has * been loaded */ protected void processThumbnailProgress(float percentageDone) { if (progressListeners != null) { Iterator it = progressListeners.iterator(); while (it.hasNext()) { IIOWriteProgressListener listener = (IIOWriteProgressListener) it.next(); listener.thumbnailProgress(this, percentageDone); } } } /** * Notifies all installed write progress listeners, by calling their * imageStarted methods, that thumbnail loading has started on the * given thumbnail of the given image. * * @param imageIndex the frame index of the image one of who's * thumbnails has started loading * @param thumbnailIndex the index of the thumbnail that has started * loading */ protected void processThumbnailStarted(int imageIndex, int thumbnailIndex) { if (progressListeners != null) { Iterator it = progressListeners.iterator(); while (it.hasNext()) { IIOWriteProgressListener listener = (IIOWriteProgressListener) it.next(); listener.thumbnailStarted(this, imageIndex, thumbnailIndex); } } } /** * Notifies all installed warning listeners, by calling their * warningOccurred methods, that a warning message has been raised. * * @param imageIndex the index of the image that was being written * when the warning was raised * @param warning the warning message * * @exception IllegalArgumentException if warning is null */ protected void processWarningOccurred(int imageIndex, String warning) { if (warningListeners != null) { Iterator it = warningListeners.iterator(); while (it.hasNext()) { IIOWriteWarningListener listener = (IIOWriteWarningListener) it.next(); listener.warningOccurred(this, imageIndex, warning); } } } /** * Notify all installed warning listeners, by calling their * warningOccurred methods, that a warning message has been raised. * The warning message is retrieved from a resource bundle, using * the given basename and keyword. * * @param imageIndex the index of the image that was being written * when the warning was raised * @param baseName the basename of the resource from which to * retrieve the warning message * @param keyword the keyword used to retrieve the warning from the * resource bundle * * @exception IllegalArgumentException if either baseName or keyword * is null * @exception IllegalArgumentException if no resource bundle is * found using baseName * @exception IllegalArgumentException if the given keyword produces * no results from the resource bundle * @exception IllegalArgumentException if the retrieved object is * not a String */ protected void processWarningOccurred(int imageIndex, String baseName, String keyword) { if (baseName == null || keyword == null) throw new IllegalArgumentException ("null argument"); ResourceBundle b = null; try { b = ResourceBundle.getBundle(baseName, getLocale()); } catch (MissingResourceException e) { throw new IllegalArgumentException ("no resource bundle found"); } Object str = null; try { str = b.getObject(keyword); } catch (MissingResourceException e) { throw new IllegalArgumentException ("no results found for keyword"); } if (! (str instanceof String)) throw new IllegalArgumentException ("retrieved object not a String"); String warning = (String) str; if (warningListeners != null) { Iterator it = warningListeners.iterator(); while (it.hasNext()) { IIOWriteWarningListener listener = (IIOWriteWarningListener) it.next(); listener.warningOccurred(this, imageIndex, warning); } } } /** * Notifies all installed write progress listeners that image * loading has been aborted by calling their writeAborted methods. */ protected void processWriteAborted() { if (progressListeners != null) { Iterator it = progressListeners.iterator(); while (it.hasNext()) { IIOWriteProgressListener listener = (IIOWriteProgressListener) it.next(); listener.writeAborted(this); } } } /** * Uninstall all write progress listeners. */ public void removeAllIIOWriteProgressListeners() { if (progressListeners != null) { progressListeners.clear(); } } /** * Uninstall all write warning listeners. */ public void removeAllIIOWriteWarningListeners() { if (progressListeners != null) { progressListeners.clear(); } } /** * Uninstall the given write progress listener. * * @param listener the listener to remove */ public void removeIIOWriteProgressListener (IIOWriteProgressListener listener) { if (listener == null) return; if (progressListeners != null) { progressListeners.remove(listener); } } /** * Uninstall the given write warning listener. * * @param listener the listener to remove */ public void removeIIOWriteWarningListener (IIOWriteWarningListener listener) { if (listener == null) return; if (warningListeners != null) { warningListeners.remove(listener); } } /** * Reset this writer's internal state. */ public void reset() { setOutput(null); setLocale(null); removeAllIIOWriteWarningListeners(); removeAllIIOWriteProgressListeners(); clearAbortRequest(); } /** * 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; } /** * Set the output destination of the given object. The output * destination must be set before many methods can be called on this * writer. (see all ImageWriter methods that throw * IllegalStateException). If input is null then the current input * source will be removed. * * @param input the output destination object * * @exception IllegalArgumentException if input is not a valid input * source for this writer and is not an ImageInputStream */ public void setOutput(Object output) { if (output != null) { // Check if its a valid output object. boolean found = false; Class[] types = null; if (originatingProvider != null) types = originatingProvider.getOutputTypes(); if (types != null) for (int i = types.length - 1; i >= 0; --i) if (types[i].isInstance(output)) found = true; if (! found) throw new IllegalArgumentException("output type not available"); } this.output = output; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -