Class ImageWriter
java.lang.Object
javax.imageio.ImageWriter
All Implemented Interfaces:
ImageTranscoder
public abstract class ImageWriter
extends Object
implements ImageTranscoder
An abstract superclass for encoding and writing images. This class must be subclassed by
classes that write out images in the context of the Java Image I/O framework.
ImageWriter objects are normally instantiated by the service provider class for the specific
format. Service provider classes are registered with the IIORegistry, which uses them for
format recognition and presentation of available format readers and writers.
See Also:
ImageReader
ImageWriteParam
IIORegistry
ImageWriterSpi
Field Summary
Fields
Modifier and Type
Field
Description
protected Locale[]
availableLocales
An array of Locales that may be used to localize warning messages and compression
setting values, or null if localization is not supported.
protected Locale
locale
The current Locale to be used for localization, or null if none has been set.
protected ImageWriterSpi
originatingProvider
The ImageWriterSpi that instantiated this object, or null if its identity is not known
or none exists.
protected Object
output
The ImageOutputStream or other Object set by setOutput and retrieved by
getOutput.
protected List<IIOWriteProgressListener>
progressListeners
A List of currently registered IIOWriteProgressListeners, initialized by default
null, which is synonymous with an empty List.
protected List<IIOWriteWarningListener>
warningListeners
A List of currently registered IIOWriteWarningListeners, initialized by default to
null, which is synonymous with an empty List.
protected List<Locale>
warningLocales
A List of Locales, one for each element of warningListeners, initialized by
default null, which is synonymous with an empty List.
Constructor Summary
Constructors
Modifier
Constructor
Description
protected
ImageWriter(ImageWriterSpi originatingProvider)
Constructs an ImageWriter and sets its originatingProvider instance variable to
the supplied value.
Method Summary
All MethodsInstance MethodsAbstract MethodsConcrete Methods
Modifier and Type
Method
Description
void
abort()
Requests that any current write operation be aborted.
protected boolean
abortRequested()
Returns true if a request to abort the current write operation has been made since the
writer was instantiated or clearAbortRequest was called.
void
addIIOWriteProgressListener(IIOWriteProgressListener listener)
Adds an IIOWriteProgressListener to the list of registered progress listeners.
void
addIIOWriteWarningListener(IIOWriteWarningListener listener)
Adds an IIOWriteWarningListener to the list of registered warning listeners.
boolean
canInsertEmpty(int imageIndex)
Returns true if the writer supports the insertion of a new, empty image at the given
index.
boolean
canInsertImage(int imageIndex)
Returns true if the writer supports the insertion of a new image at the given index.
boolean
canRemoveImage(int imageIndex)
Returns true if the writer supports the removal of an existing image at the given index.
boolean
canReplaceImageMetadata(int imageIndex)
Returns true if it is possible to replace the image metadata associated with an existing
image with index imageIndex.
boolean
canReplacePixels(int imageIndex)
Returns true if the writer allows pixels of the given image to be replaced using the
replacePixels methods.
boolean
canReplaceStreamMetadata()
Returns true if it is possible to replace the stream metadata already present in the
output.
boolean
canWriteEmpty()
Returns true if the writer supports the writing of a complete image stream consisting
of a single image with undefined pixel values and associated metadata and thumbnails
to the output.
boolean
canWriteRasters()
Returns true if the methods that take an IIOImage parameter are capable of dealing
with a Raster (as opposed to RenderedImage) source image.
boolean
canWriteSequence()
Returns true if the writer is able to append an image to an image stream that already
contains header information and possibly prior images.
protected void
clearAbortRequest()
Clears any previous abort request.
void
dispose()
Allows any resources held by this object to be released.
void
endInsertEmpty()
Completes the insertion of a new image that was begun with a prior call to
prepareInsertEmpty.
void
endReplacePixels()
Terminates a sequence of calls to replacePixels.
void
endWriteEmpty()
Completes the writing of a new image that was begun with a prior call to
prepareWriteEmpty.
void
endWriteSequence()
Completes the writing of a sequence of images begun with prepareWriteSequence.
Locale[]
getAvailableLocales()
Returns an array of Locales that may be used to localize warning listeners and
compression settings.
abstract IIOMetadata
getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param)
Returns an IIOMetadata object containing default values for encoding an image of the
given type.
abstract IIOMetadata
getDefaultStreamMetadata(ImageWriteParam param)
Returns an IIOMetadata object containing default values for encoding a stream of
images.
ImageWriteParam
getDefaultWriteParam()
Returns a new ImageWriteParam object of the appropriate type for this file format
containing default values, that is, those values that would be used if no
ImageWriteParam object were specified.
Locale
getLocale()
Returns the currently set Locale, or null if none has been set.
int
getNumThumbnailsSupported(ImageTypeSpecifier imageType,
ImageWriteParam param, IIOMetadata streamMetadata, IIOMetadata
imageMetadata)
Returns the number of thumbnails supported by the format being written, given the
image type and any additional write parameters and metadata objects that will be used
during encoding.
ImageWriterSpi
getOriginatingProvider()
Returns the ImageWriterSpi object that created this ImageWriter, or null if this
object was not created through the IIORegistry.
Object
getOutput()
Returns the ImageOutputStream or other Object set by the most recent call to the
setOutput method.
Dimension[]
getPreferredThumbnailSizes(ImageTypeSpecifier imageType,
ImageWriteParam param, IIOMetadata streamMetadata, IIOMetadata
imageMetadata)
Returns an array of Dimensions indicating the legal size ranges for thumbnail images
as they will be encoded in the output file or stream.
void
prepareInsertEmpty(int imageIndex, ImageTypeSpecifier imageType,
int width, int height, IIOMetadata imageMetadata, List<? extends
BufferedImage> thumbnails, ImageWriteParam param)
Begins the insertion of a new image with undefined pixel values into an existing image
stream.
void
prepareReplacePixels(int imageIndex, Rectangle region)
Prepares the writer to handle a series of calls to the replacePixels methods.
void
prepareWriteEmpty(IIOMetadata streamMetadata, ImageTypeSpecifier
imageType, int width, int height, IIOMetadata imageMetadata,
List<? extends BufferedImage> thumbnails, ImageWriteParam param)
Begins the writing of a complete image stream, consisting of a single image with
undefined pixel values and associated metadata and thumbnails, to the output.
void
prepareWriteSequence(IIOMetadata streamMetadata)
Prepares a stream to accept a series of subsequent writeToSequence calls, using the
provided stream metadata object.
protected void
processImageComplete()
Broadcasts the completion of an image write to all registered
IIOWriteProgressListeners by calling their imageComplete method.
protected void
processImageProgress(float percentageDone)
Broadcasts the current percentage of image completion to all registered
IIOWriteProgressListeners by calling their imageProgress method.
protected void
processImageStarted(int imageIndex)
Broadcasts the start of an image write to all registered
IIOWriteProgressListeners by calling their imageStarted method.
protected void
processThumbnailComplete()
Broadcasts the completion of a thumbnail write to all registered
IIOWriteProgressListeners by calling their thumbnailComplete method.
protected void
processThumbnailProgress(float percentageDone)
Broadcasts the current percentage of thumbnail completion to all registered
IIOWriteProgressListeners by calling their thumbnailProgress method.
protected void
processThumbnailStarted(int imageIndex, int thumbnailIndex)
Broadcasts the start of a thumbnail write to all registered
IIOWriteProgressListeners by calling their thumbnailStarted method.
protected void
processWarningOccurred(int imageIndex, String warning)
Broadcasts a warning message to all registered IIOWriteWarningListeners by
calling their warningOccurred method.
protected void
processWarningOccurred(int imageIndex, String baseName, String
keyword)
Broadcasts a localized warning message to all registered
IIOWriteWarningListeners by calling their warningOccurred method with a
string taken from a ResourceBundle.
protected void
processWriteAborted()
Broadcasts that the write has been aborted to all registered
IIOWriteProgressListeners by calling their writeAborted method.
void
removeAllIIOWriteProgressListeners()
Removes all currently registered IIOWriteProgressListener objects.
void
removeAllIIOWriteWarningListeners()
Removes all currently registered IIOWriteWarningListener objects.
void
removeIIOWriteProgressListener(IIOWriteProgressListener listener)
Removes an IIOWriteProgressListener from the list of registered progress
listeners.
void
removeIIOWriteWarningListener(IIOWriteWarningListener listener)
Removes an IIOWriteWarningListener from the list of registered warning
listeners.
void
removeImage(int imageIndex)
Removes an image from the stream.
void
replaceImageMetadata(int imageIndex, IIOMetadata imageMetadata)
Replaces the image metadata associated with an existing image.
void
replacePixels(Raster raster, ImageWriteParam param)
Replaces a portion of an image already present in the output with a portion of the given
Raster.
void
replacePixels(RenderedImage image, ImageWriteParam param)
Replaces a portion of an image already present in the output with a portion of the given
image.
void
replaceStreamMetadata(IIOMetadata streamMetadata)
Replaces the stream metadata in the output with new information.
void
reset()
Restores the ImageWriter to its initial state.
void
setLocale(Locale locale)
Sets the current Locale of this ImageWriter to the given value.
void
setOutput(Object output)
Sets the destination to the given ImageOutputStream or other Object.
void
write(RenderedImage image)
Appends a complete image stream consisting of a single image with default metadata
and thumbnails to the output.
void
write(IIOImage image)
Appends a complete image stream containing a single image with default metadata and
thumbnails to the output.
abstract void
write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam
param)
Appends a complete image stream containing a single image and associated stream and
image metadata and thumbnails to the output.
void
writeInsert(int imageIndex, IIOImage image, ImageWriteParam
param)
Inserts a new image into an existing image stream.
void
writeToSequence(IIOImage image, ImageWriteParam param)
Appends a single image and possibly associated metadata and thumbnails, to the
output.
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
toString, wait, wait, wait
Methods declared in interface javax.imageio.ImageTranscoder
convertImageMetadata, convertStreamMetadata
Field Details
originatingProvider
protected ImageWriterSpi originatingProvider
The ImageWriterSpi that instantiated this object, or null if its identity is not
known or none exists. By default it is initialized to null.
output
protected Object output
The ImageOutputStream or other Object set by setOutput and retrieved by
getOutput. By default it is initialized to null.
availableLocales
protected Locale[] availableLocales
An array of Locales that may be used to localize warning messages and
compression setting values, or null if localization is not supported. By default it
is initialized to null.
locale
protected Locale locale
The current Locale to be used for localization, or null if none has been set. By
default it is initialized to null.
warningListeners
protected List<IIOWriteWarningListener> warningListeners
A List of currently registered IIOWriteWarningListeners, initialized by
default to null, which is synonymous with an empty List.
warningLocales
protected List<Locale> warningLocales
A List of Locales, one for each element of warningListeners, initialized by
default null, which is synonymous with an empty List.
progressListeners
protected List<IIOWriteProgressListener> progressListeners
A List of currently registered IIOWriteProgressListeners, initialized by
default null, which is synonymous with an empty List.
Constructor Details
ImageWriter
protected ImageWriter(ImageWriterSpi originatingProvider)
Constructs an ImageWriter and sets its originatingProvider instance
variable to the supplied value.
Subclasses that make use of extensions should provide a constructor with
signature (ImageWriterSpi, Object) in order to retrieve the extension
object. If the extension object is unsuitable, an IllegalArgumentException
should be thrown.
Parameters:
originatingProvider - the ImageWriterSpi that is constructing this
object, or null.
Method Details
getOriginatingProvider
public ImageWriterSpi getOriginatingProvider()
Returns the ImageWriterSpi object that created this ImageWriter, or null
if this object was not created through the IIORegistry.
The default implementation returns the value of the originatingProvider
instance variable.
Returns:
an ImageWriterSpi, or null.
See Also:
ImageWriterSpi
setOutput