public class

JPEGImageWriter

extends ImageWriter
java.lang.Object
   ↳ javax.imageio.ImageWriter
     ↳ com.sun.imageio.plugins.jpeg.JPEGImageWriter

Summary

Constants
int WARNING_DEST_IGNORED
int WARNING_DEST_METADATA_ADOBE_MISMATCH
int WARNING_DEST_METADATA_COMP_MISMATCH
int WARNING_DEST_METADATA_JFIF_MISMATCH
int WARNING_FORCING_JFIF
int WARNING_IGNORING_THUMBS
int WARNING_ILLEGAL_THUMBNAIL
int WARNING_IMAGE_METADATA_ADOBE_MISMATCH
int WARNING_IMAGE_METADATA_JFIF_MISMATCH
int WARNING_METADATA_ADJUSTED_FOR_THUMB
int WARNING_METADATA_NOT_JPEG_FOR_RASTER
int WARNING_NO_BANDS_ON_INDEXED
int WARNING_NO_GRAY_THUMB_AS_INDEXED
int WARNING_NO_RGB_THUMB_AS_INDEXED
int WARNING_STREAM_METADATA_IGNORED
int WARNING_THUMB_CLIPPED
[Expand]
Inherited Fields
From class javax.imageio.ImageWriter
Public Constructors
JPEGImageWriter(ImageWriterSpi originator)
Public Methods
synchronized void abort()
Requests that any current write operation be aborted.
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.
IIOMetadata convertImageMetadata(IIOMetadata inData, ImageTypeSpecifier imageType, ImageWriteParam param)
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.
IIOMetadata convertStreamMetadata(IIOMetadata inData, ImageWriteParam param)
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.
void dispose()
Allows any resources held by this object to be released.
void endWriteSequence()
Completes the writing of a sequence of images begun with prepareWriteSequence.
IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, ImageWriteParam param)
Returns an IIOMetadata object containing default values for encoding an image of the given type.
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.
int getNumThumbnailsSupported(ImageTypeSpecifier imageType, ImageWriteParam param, IIOMetadata streamMetadata, IIOMetadata imageMetadata)
Returns the number of thumbnails suported by the format being written, given the image type and any additional write parameters and metadata objects that will be used during encoding.
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 prepareWriteSequence(IIOMetadata streamMetadata)
Prepares a stream to accept a series of subsequent writeToSequence calls, using the provided stream metadata object.
void reset()
Restores the ImageWriter to its initial state.
void setOutput(Object output)
Sets the destination to the given ImageOutputStream or other Object.
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 writeToSequence(IIOImage image, ImageWriteParam param)
Appends a single image and possibly associated metadata and thumbnails, to the output.
[Expand]
Inherited Methods
From class javax.imageio.ImageWriter
From class java.lang.Object
From interface javax.imageio.ImageTranscoder

Constants

protected static final int WARNING_DEST_IGNORED

Constant Value: 0 (0x00000000)

protected static final int WARNING_DEST_METADATA_ADOBE_MISMATCH

Constant Value: 4 (0x00000004)

protected static final int WARNING_DEST_METADATA_COMP_MISMATCH

Constant Value: 2 (0x00000002)

protected static final int WARNING_DEST_METADATA_JFIF_MISMATCH

Constant Value: 3 (0x00000003)

protected static final int WARNING_FORCING_JFIF

Constant Value: 11 (0x0000000b)

protected static final int WARNING_IGNORING_THUMBS

Constant Value: 10 (0x0000000a)

protected static final int WARNING_ILLEGAL_THUMBNAIL

Constant Value: 9 (0x00000009)

protected static final int WARNING_IMAGE_METADATA_ADOBE_MISMATCH

Constant Value: 6 (0x00000006)

protected static final int WARNING_IMAGE_METADATA_JFIF_MISMATCH

Constant Value: 5 (0x00000005)

protected static final int WARNING_METADATA_ADJUSTED_FOR_THUMB

Constant Value: 13 (0x0000000d)

protected static final int WARNING_METADATA_NOT_JPEG_FOR_RASTER

Constant Value: 7 (0x00000007)

protected static final int WARNING_NO_BANDS_ON_INDEXED

Constant Value: 8 (0x00000008)

protected static final int WARNING_NO_GRAY_THUMB_AS_INDEXED

Constant Value: 15 (0x0000000f)

protected static final int WARNING_NO_RGB_THUMB_AS_INDEXED

Constant Value: 14 (0x0000000e)

protected static final int WARNING_STREAM_METADATA_IGNORED

Constant Value: 1 (0x00000001)

protected static final int WARNING_THUMB_CLIPPED

Constant Value: 12 (0x0000000c)

Public Constructors

public JPEGImageWriter (ImageWriterSpi originator)

Public Methods

public synchronized void abort ()

Requests that any current write operation be aborted. The contents of the output following the abort will be undefined.

Writers should call clearAbortRequest at the beginning of each write operation, and poll the value of abortRequested regularly during the write.

public 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. If this method returns false, then those methods will throw an UnsupportedOperationException if supplied with an IIOImage containing a Raster.

The default implementation returns false.

Returns
  • true if Raster sources are supported.

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

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.

An optional ImageWriteParam may be supplied for cases where it may affect the structure of the image metadata.

If the supplied ImageWriteParam contains optional setting values not understood by this writer or transcoder, they will be ignored.

Parameters
inData an IIOMetadata object representing image metadata, used to initialize the state of the returned object.
imageType an ImageTypeSpecifier indicating the layout and color information of the image with which the metadata will be associated.
param an ImageWriteParam that will be used to encode the image, or null.
Returns
  • an IIOMetadata object, or null if the plug-in does not provide metadata encoding capabilities.

public IIOMetadata convertStreamMetadata (IIOMetadata inData, ImageWriteParam param)

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.

An optional ImageWriteParam may be supplied for cases where it may affect the structure of the stream metadata.

If the supplied ImageWriteParam contains optional setting values not understood by this writer or transcoder, they will be ignored.

Parameters
inData an IIOMetadata object representing stream metadata, used to initialize the state of the returned object.
param an ImageWriteParam that will be used to encode the image, or null.
Returns
  • an IIOMetadata object, or null if the plug-in does not provide metadata encoding capabilities.

public void dispose ()

Allows any resources held by this object to be released. The result of calling any other method (other than finalize) subsequent to a call to this method is undefined.

It is important for applications to call this method when they know they will no longer be using this ImageWriter. Otherwise, the writer may continue to hold on to resources indefinitely.

The default implementation of this method in the superclass does nothing. Subclass implementations should ensure that all resources, especially native resources, are released.

public void endWriteSequence ()

Completes the writing of a sequence of images begun with prepareWriteSequence. Any stream metadata that should come at the end of the sequence of images is written out, and any header information at the beginning of the sequence is patched up if necessary. If the output is an ImageOutputStream, data through the stream metadata at the end of the sequence are flushed and need not be readable or writable.

If canWriteSequence returns false, this method will throw an UnsupportedOperationException.

The default implementation throws an IllegalStateException if the output is null, and otherwise throws an UnsupportedOperationException.

Throws
IOException

public IIOMetadata getDefaultImageMetadata (ImageTypeSpecifier imageType, ImageWriteParam param)

Returns an IIOMetadata object containing default values for encoding an image of the given type. The contents of the object may be manipulated using either the XML tree structure returned by the IIOMetadata.getAsTree method, an IIOMetadataController object, or via plug-in specific interfaces, and the resulting data supplied to one of the write methods that take a stream metadata parameter.

An optional ImageWriteParam may be supplied for cases where it may affect the structure of the image metadata.

If the supplied ImageWriteParam contains optional setting values not supported by this writer (e.g. progressive encoding or any format-specific settings), they will be ignored.

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

public IIOMetadata getDefaultStreamMetadata (ImageWriteParam param)

Returns an IIOMetadata object containing default values for encoding a stream of images. The contents of the object may be manipulated using either the XML tree structure returned by the IIOMetadata.getAsTree method, an IIOMetadataController object, or via plug-in specific interfaces, and the resulting data supplied to one of the write methods that take a stream metadata parameter.

An optional ImageWriteParam may be supplied for cases where it may affect the structure of the stream metadata.

If the supplied ImageWriteParam contains optional setting values not supported by this writer (e.g. progressive encoding or any format-specific settings), they will be ignored.

Writers that do not make use of stream metadata (e.g., writers for single-image formats) should return null.

Parameters
param an ImageWriteParam that will be used to encode the image, or null.
Returns
  • an IIOMetadata object.

public 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. This is useful as a starting point for tweaking just a few parameters and otherwise leaving the default settings alone.

The default implementation constructs and returns a new ImageWriteParam object that does not allow tiling, progressive encoding, or compression, and that will be localized for the current Locale (i.e., what you would get by calling new ImageWriteParam(getLocale()).

Individual plug-ins may return an instance of ImageWriteParam with additional optional features enabled, or they may return an instance of a plug-in specific subclass of ImageWriteParam.

Returns
  • a new ImageWriteParam object containing default values.

public int getNumThumbnailsSupported (ImageTypeSpecifier imageType, ImageWriteParam param, IIOMetadata streamMetadata, IIOMetadata imageMetadata)

Returns the number of thumbnails suported by the format being written, given the image type and any additional write parameters and metadata objects that will be used during encoding. A return value of -1 indicates that insufficient information is available.

An ImageWriteParam may optionally be supplied for cases where it may affect thumbnail handling.

If the supplied ImageWriteParam contains optional setting values not supported by this writer (e.g. progressive encoding or any format-specific settings), they will be ignored.

The default implementation returns 0.

Parameters
imageType an ImageTypeSpecifier indicating the type of image to be written, or null.
param the ImageWriteParam that will be used for writing, or null.
streamMetadata an IIOMetadata object that will be used for writing, or null.
imageMetadata an IIOMetadata object that will be used for writing, or null.
Returns
  • the number of thumbnails that may be written given the supplied parameters, or -1 if insufficient information is available.

public 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. This information is merely advisory; the writer will resize any supplied thumbnails as necessary.

The information is returned as a set of pairs; the first element of a pair contains an (inclusive) minimum width and height, and the second element contains an (inclusive) maximum width and height. Together, each pair defines a valid range of sizes. To specify a fixed size, the same width and height will appear for both elements. A return value of null indicates that the size is arbitrary or unknown.

An ImageWriteParam may optionally be supplied for cases where it may affect thumbnail handling.

If the supplied ImageWriteParam contains optional setting values not supported by this writer (e.g. progressive encoding or any format-specific settings), they will be ignored.

The default implementation returns null.

Parameters
imageType an ImageTypeSpecifier indicating the type of image to be written, or null.
param the ImageWriteParam that will be used for writing, or null.
streamMetadata an IIOMetadata object that will be used for writing, or null.
imageMetadata an IIOMetadata object that will be used for writing, or null.
Returns
  • an array of Dimensions with an even length of at least two, or null.

public void prepareWriteSequence (IIOMetadata streamMetadata)

Prepares a stream to accept a series of subsequent writeToSequence calls, using the provided stream metadata object. The metadata will be written to the stream if it should precede the image data. If the argument is null, default stream metadata is used.

If the output is an ImageOutputStream, the existing contents of the output prior to the current seek position are flushed, and need not be readable or writable. If the format requires that endWriteSequence be able to rewind to patch up the header information, such as for a sequence of images in a single TIFF file, then the metadata written by this method must remain in a writable portion of the stream. Other formats may flush the stream after this method and after each image.

If canWriteSequence returns false, this method will throw an UnsupportedOperationException.

The output must have been set beforehand using either the setOutput method.

The default implementation throws an IllegalStateException if the output is null, and otherwise throws an UnsupportedOperationException.

Parameters
streamMetadata A stream metadata object, or null.
Throws
IOException

public void reset ()

Restores the ImageWriter to its initial state.

The default implementation calls setOutput(null), setLocale(null), removeAllIIOWriteWarningListeners(), removeAllIIOWriteProgressListeners(), and clearAbortRequest.

public void setOutput (Object output)

Sets the destination to the given ImageOutputStream or other Object. The destination is assumed to be ready to accept data, and will not be closed at the end of each write. This allows distributed imaging applications to transmit a series of images over a single network connection. If output is null, any currently set output will be removed.

If output is an ImageOutputStream, calls to the write, writeToSequence, and prepareWriteEmpty/endWriteEmpty methods will preserve the existing contents of the stream. Other write methods, such as writeInsert, replaceStreamMetadata, replaceImageMetadata, replacePixels, prepareInsertEmpty/endInsertEmpty, and endWriteSequence, require the full contents of the stream to be readable and writable, and may alter any portion of the stream.

Use of a general Object other than an ImageOutputStream is intended for writers that interact directly with an output device or imaging protocol. The set of legal classes is advertised by the writer's service provider's getOutputTypes method; most writers will return a single-element array containing only ImageOutputStream.class to indicate that they accept only an ImageOutputStream.

The default implementation sets the output instance variable to the value of output after checking output against the set of classes advertised by the originating provider, if there is one.

Parameters
output the ImageOutputStream or other Object to use for future writing.

public 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. Any necessary header information is included. If the output is an ImageOutputStream, its existing contents prior to the current seek position are not affected, and need not be readable or writable.

The output must have been set beforehand using the setOutput method.

Stream metadata may optionally be supplied; if it is null, default stream metadata will be used.

If canWriteRasters returns true, the IIOImage may contain a Raster source. Otherwise, it must contain a RenderedImage source.

The supplied thumbnails will be resized if needed, and any thumbnails in excess of the supported number will be ignored. If the format requires additional thumbnails that are not provided, the writer should generate them internally.

An ImageWriteParam may optionally be supplied to control the writing process. If param is null, a default write param will be used.

If the supplied ImageWriteParam contains optional setting values not supported by this writer (e.g. progressive encoding or any format-specific settings), they will be ignored.

Parameters
streamMetadata an IIOMetadata object representing stream metadata, or null to use default values.
image an IIOImage object containing an image, thumbnails, and metadata to be written.
param an ImageWriteParam, or null to use a default ImageWriteParam.
Throws
IOException

public void writeToSequence (IIOImage image, ImageWriteParam param)

Appends a single image and possibly associated metadata and thumbnails, to the output. If the output is an ImageOutputStream, the existing contents of the output prior to the current seek position may be flushed, and need not be readable or writable, unless the plug-in needs to be able to patch up the header information when endWriteSequence is called (e.g. TIFF).

If canWriteSequence returns false, this method will throw an UnsupportedOperationException.

The output must have been set beforehand using the setOutput method.

prepareWriteSequence must have been called beforehand, or an IllegalStateException is thrown.

If canWriteRasters returns true, the IIOImage may contain a Raster source. Otherwise, it must contain a RenderedImage source.

The supplied thumbnails will be resized if needed, and any thumbnails in excess of the supported number will be ignored. If the format requires additional thumbnails that are not provided, the writer will generate them internally.

An ImageWriteParam may optionally be supplied to control the writing process. If param is null, a default write param will be used.

If the supplied ImageWriteParam contains optional setting values not supported by this writer (e.g. progressive encoding or any format-specific settings), they will be ignored.

The default implementation throws an IllegalStateException if the output is null, and otherwise throws an UnsupportedOperationException.

Parameters
image an IIOImage object containing an image, thumbnails, and metadata to be written.
param an ImageWriteParam, or null to use a default ImageWriteParam.
Throws
IOException