APIdia Launch Partner
Top Description Fields Constructors Methods
javax.imageio

public abstract Class ImageWriter

extends Object
implements ImageTranscoder
Class Inheritance
All Implemented Interfaces
javax.imageio.ImageTranscoder
Known Direct Subclasses
com.sun.imageio.plugins.bmp.BMPImageWriter, com.sun.imageio.plugins.gif.GIFImageWriter, com.sun.imageio.plugins.jpeg.JPEGImageWriter, com.sun.imageio.plugins.png.PNGImageWriter, com.sun.imageio.plugins.tiff.TIFFImageWriter, com.sun.imageio.plugins.wbmp.WBMPImageWriter
Imports
java.awt.Dimension, .Rectangle, java.awt.image.BufferedImage, .RenderedImage, .Raster, java.io.IOException, java.util.ArrayList, .List, .Locale, .MissingResourceException, .ResourceBundle, javax.imageio.event.IIOWriteWarningListener, .IIOWriteProgressListener, javax.imageio.metadata.IIOMetadata, javax.imageio.stream.ImageOutputStream, javax.imageio.spi.ImageWriterSpi

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, javax.imageio.spi.IIORegistry, javax.imageio.spi.ImageWriterSpi

Field Summary

Modifier and TypeField and Description
private boolean
abortFlag

If true, the current write operation should be aborted.

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

AccessConstructor and Description
protected
ImageWriter(ImageWriterSpi
the ImageWriterSpi that is constructing this object, or null.
originatingProvider
)

Constructs an ImageWriter and sets its originatingProvider instance variable to the supplied value.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
abort()

Requests that any current write operation be aborted.

protected synchronized boolean

Returns:

true if the current write operation should be aborted.
abortRequested
()

Returns true if a request to abort the current write operation has been made since the writer was instantiated or clearAbortRequest was called.

public void
addIIOWriteProgressListener(IIOWriteProgressListener
an IIOWriteProgressListener to be registered.
listener
)

Adds an IIOWriteProgressListener to the list of registered progress listeners.

public void
addIIOWriteWarningListener(IIOWriteWarningListener
an IIOWriteWarningListener to be registered.
listener
)

Adds an IIOWriteWarningListener to the list of registered warning listeners.

public boolean

Returns:

true if an empty image may be inserted at the given index.
canInsertEmpty
(int
the index at which the image is to be inserted.
imageIndex
)

Returns true if the writer supports the insertion of a new, empty image at the given index.

public boolean

Returns:

true if an image may be inserted at the given index.
canInsertImage
(int
the index at which the image is to be inserted.
imageIndex
)

Returns true if the writer supports the insertion of a new image at the given index.

public boolean

Returns:

true if it is possible to remove the given image.
canRemoveImage
(int
the index of the image to be removed.
imageIndex
)

Returns true if the writer supports the removal of an existing image at the given index.

public boolean

Returns:

true if the image metadata of the given image can be replaced.
canReplaceImageMetadata
(int
the index of the image whose metadata is to be replaced.
imageIndex
)

Returns true if it is possible to replace the image metadata associated with an existing image with index imageIndex.

public boolean

Returns:

true if the pixels of the given image can be replaced.
canReplacePixels
(int
the index of the image whose pixels are to be replaced.
imageIndex
)

Returns true if the writer allows pixels of the given image to be replaced using the replacePixels methods.

public boolean

Returns:

true if replacement of stream metadata is allowed.
canReplaceStreamMetadata
()

Returns true if it is possible to replace the stream metadata already present in the output.

public boolean

Returns:

true if the writing of complete image stream with contents to be defined later is supported.
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.

public boolean

Returns:

true if Raster sources are supported.
canWriteRasters
()

Returns true if the methods that take an IIOImage parameter are capable of dealing with a Raster (as opposed to RenderedImage) source image.

public boolean

Returns:

true if images may be appended sequentially.
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 synchronized void
clearAbortRequest()

Clears any previous abort request.

public abstract IIOMetadata
convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param)

Redeclares javax.imageio.ImageTranscoder.convertImageMetadata.

Returns an IIOMetadata object that may be used for encoding and optionally modified using its document interfaces or other interfaces specific to the writer plug-in that will be used for encoding.

public abstract IIOMetadata
convertStreamMetadata(IIOMetadata inData, ImageWriteParam param)

Redeclares javax.imageio.ImageTranscoder.convertStreamMetadata.

Returns an IIOMetadata object that may be used for encoding and optionally modified using its document interfaces or other interfaces specific to the writer plug-in that will be used for encoding.

public void
dispose()

Allows any resources held by this object to be released.

public void
endInsertEmpty()

Completes the insertion of a new image that was begun with a prior call to prepareInsertEmpty.

public void
endReplacePixels()

Terminates a sequence of calls to replacePixels.

public void
endWriteEmpty()

Completes the writing of a new image that was begun with a prior call to prepareWriteEmpty.

public void
endWriteSequence()

Completes the writing of a sequence of images begun with prepareWriteSequence.

public Locale[]

Returns:

an array of Locales that may be used as arguments to setLocale, or null.
getAvailableLocales
()

Returns an array of Locales that may be used to localize warning listeners and compression settings.

public abstract IIOMetadata

Returns:

an IIOMetadata object.
getDefaultImageMetadata
(ImageTypeSpecifier
an ImageTypeSpecifier indicating the format of the image to be written later.
imageType
,
ImageWriteParam
an ImageWriteParam that will be used to encode the image, or null.
param
)

Returns an IIOMetadata object containing default values for encoding an image of the given type.

public abstract IIOMetadata

Returns:

an IIOMetadata object.
getDefaultStreamMetadata
(ImageWriteParam
an ImageWriteParam that will be used to encode the image, or null.
param
)

Returns an IIOMetadata object containing default values for encoding a stream of images.

public ImageWriteParam

Returns:

a new ImageWriteParam object containing default values.
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.

public Locale

Returns:

the current Locale, or null.
getLocale
()

Returns the currently set Locale, or null if none has been set.

public int

Returns:

the number of thumbnails that may be written given the supplied parameters, or -1 if insufficient information is available.
getNumThumbnailsSupported
(ImageTypeSpecifier
an ImageTypeSpecifier indicating the type of image to be written, or null.
imageType
,
ImageWriteParam
the ImageWriteParam that will be used for writing, or null.
param
,
IIOMetadata
an IIOMetadata object that will be used for writing, or null.
streamMetadata
,
IIOMetadata
an IIOMetadata object that will be used for writing, or null.
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.

public ImageWriterSpi

Returns:

an ImageWriterSpi, or null.
getOriginatingProvider
()

Returns the ImageWriterSpi object that created this ImageWriter, or null if this object was not created through the IIORegistry.

public Object

Returns:

the Object that was specified using setOutput, or null.
getOutput
()

Returns the ImageOutputStream or other Object set by the most recent call to the setOutput method.

public Dimension[]

Returns:

an array of Dimensions with an even length of at least two, or null.
getPreferredThumbnailSizes
(ImageTypeSpecifier
an ImageTypeSpecifier indicating the type of image to be written, or null.
imageType
,
ImageWriteParam
the ImageWriteParam that will be used for writing, or null.
param
,
IIOMetadata
an IIOMetadata object that will be used for writing, or null.
streamMetadata
,
IIOMetadata
an IIOMetadata object that will be used for writing, or null.
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.

public void
prepareInsertEmpty(int
the index at which to write the image.
imageIndex
,
ImageTypeSpecifier
an ImageTypeSpecifier describing the layout of the image.
imageType
,
int
the width of the image.
width
,
int
the height of the image.
height
,
IIOMetadata
an IIOMetadata object representing image metadata, or null.
imageMetadata
,
List<? extends BufferedImage>
a List of BufferedImage thumbnails for this image, or null.
thumbnails
,
ImageWriteParam
an ImageWriteParam, or null to use a default ImageWriteParam.
param
)

Begins the insertion of a new image with undefined pixel values into an existing image stream.

public void
prepareReplacePixels(int
the index of the image whose pixels are to be replaced.
imageIndex
,
Rectangle
a Rectangle that will be used to clip future pixel regions.
region
)

Prepares the writer to handle a series of calls to the replacePixels methods.

public void
prepareWriteEmpty(IIOMetadata
an IIOMetadata object representing stream metadata, or null to use default values.
streamMetadata
,
ImageTypeSpecifier
an ImageTypeSpecifier describing the layout of the image.
imageType
,
int
the width of the image.
width
,
int
the height of the image.
height
,
IIOMetadata
an IIOMetadata object representing image metadata, or null.
imageMetadata
,
List<? extends BufferedImage>
a List of BufferedImage thumbnails for this image, or null.
thumbnails
,
ImageWriteParam
an ImageWriteParam, or null to use a default 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.

public void
prepareWriteSequence(IIOMetadata
A stream metadata object, or null.
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
the current percentage of completion, as a float.
percentageDone
)

Broadcasts the current percentage of image completion to all registered IIOWriteProgressListeners by calling their imageProgress method.

protected void
processImageStarted(int
the index of the image about to be written.
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
the current percentage of completion, as a float.
percentageDone
)

Broadcasts the current percentage of thumbnail completion to all registered IIOWriteProgressListeners by calling their thumbnailProgress method.

protected void
processThumbnailStarted(int
the index of the image associated with the thumbnail.
imageIndex
,
int
the index of the thumbnail.
thumbnailIndex
)

Broadcasts the start of a thumbnail write to all registered IIOWriteProgressListeners by calling their thumbnailStarted method.

protected void
processWarningOccurred(int
the index of the image on which the warning occurred.
imageIndex
,
String
the warning message.
warning
)

Broadcasts a warning message to all registered IIOWriteWarningListeners by calling their warningOccurred method.

protected void
processWarningOccurred(int
the index of the image on which the warning occurred.
imageIndex
,
String
the base name of a set of ResourceBundles containing localized warning messages.
baseName
,
String
the keyword used to index the warning message within the set of ResourceBundles.
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.

public void
removeAllIIOWriteProgressListeners()

Removes all currently registered IIOWriteProgressListener objects.

public void
removeAllIIOWriteWarningListeners()

Removes all currently registered IIOWriteWarningListener objects.

public void
removeIIOWriteProgressListener(IIOWriteProgressListener
an IIOWriteProgressListener to be deregistered.
listener
)

Removes an IIOWriteProgressListener from the list of registered progress listeners.

public void
removeIIOWriteWarningListener(IIOWriteWarningListener
an IIOWriteWarningListener to be deregistered.
listener
)

Removes an IIOWriteWarningListener from the list of registered warning listeners.

public void
removeImage(int
the index of the image to be removed.
imageIndex
)

Removes an image from the stream.

public void
replaceImageMetadata(int
the index of the image whose metadata is to be replaced.
imageIndex
,
IIOMetadata
an IIOMetadata object representing image metadata, or null.
imageMetadata
)

Replaces the image metadata associated with an existing image.

public void
replacePixels(RenderedImage
a RenderedImage containing source pixels.
image
,
ImageWriteParam
an ImageWriteParam, or null to use a default ImageWriteParam.
param
)

Replaces a portion of an image already present in the output with a portion of the given image.

public void
replacePixels(Raster
a Raster containing source pixels.
raster
,
ImageWriteParam
an ImageWriteParam, or null to use a default ImageWriteParam.
param
)

Replaces a portion of an image already present in the output with a portion of the given Raster.

public void
replaceStreamMetadata(IIOMetadata
an IIOMetadata object representing stream metadata, or null to use default values.
streamMetadata
)

Replaces the stream metadata in the output with new information.

public void
reset()

Restores the ImageWriter to its initial state.

public void
setLocale(Locale
the desired Locale, or null.
locale
)

Sets the current Locale of this ImageWriter to the given value.

public void
setOutput(Object
the ImageOutputStream or other Object to use for future writing.
output
)

Sets the destination to the given ImageOutputStream or other Object.

private void
public abstract void
write(IIOMetadata
an IIOMetadata object representing stream metadata, or null to use default values.
streamMetadata
,
IIOImage
an IIOImage object containing an image, thumbnails, and metadata to be written.
image
,
ImageWriteParam
an ImageWriteParam, or null to use a default ImageWriteParam.
param
)

Appends a complete image stream containing a single image and associated stream and image metadata and thumbnails to the output.

public void
write(IIOImage
an IIOImage object containing an image, thumbnails, and metadata to be written.
image
)

Appends a complete image stream containing a single image with default metadata and thumbnails to the output.

public void
write(RenderedImage
a RenderedImage to be written.
image
)

Appends a complete image stream consisting of a single image with default metadata and thumbnails to the output.

public void
writeInsert(int
the index at which to write the image.
imageIndex
,
IIOImage
an IIOImage object containing an image, thumbnails, and metadata to be written.
image
,
ImageWriteParam
an ImageWriteParam, or null to use a default ImageWriteParam.
param
)

Inserts a new image into an existing image stream.

public void
writeToSequence(IIOImage
an IIOImage object containing an image, thumbnails, and metadata to be written.
image
,
ImageWriteParam
an ImageWriteParam, or null to use a default ImageWriteParam.
param
)

Appends a single image and possibly associated metadata and thumbnails, to the output.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait