Class ImageWriterSpi
- All Implemented Interfaces:
RegisterableService
public abstract class ImageWriterSpi extends ImageReaderWriterSpi
ImageWriters. For more information on service provider classes, see the class comment for the IIORegistry class. Each ImageWriterSpi provides several types of information about the ImageWriter class with which it is associated.
The name of the vendor who defined the SPI class and a brief description of the class are available via the getVendorName, getDescription, and getVersion methods. These methods may be internationalized to provide locale-specific output. These methods are intended mainly to provide short, human-writable information that might be used to organize a pop-up menu or other list.
Lists of format names, file suffixes, and MIME types associated with the service may be obtained by means of the getFormatNames, getFileSuffixes, and getMIMEType methods. These methods may be used to identify candidate ImageWriters for writing a particular file or stream based on manual format selection, file naming, or MIME associations.
A more reliable way to determine which ImageWriters are likely to be able to parse a particular data stream is provided by the canEncodeImage method. This methods allows the service provider to inspect the actual image contents.
Finally, an instance of the ImageWriter class associated with this service provider may be obtained by calling the createWriterInstance method. Any heavyweight initialization, such as the loading of native libraries or creation of large tables, should be deferred at least until the first invocation of this method.
- See Also:
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
protected Class<?>[] |
outputTypes |
An array of Class objects to be returned from getOutputTypes, initially null. |
protected String[] |
readerSpiNames |
An array of strings to be returned from getImageReaderSpiNames, initially null. |
static final Class<?>[] |
STANDARD_OUTPUT_TYPE |
Deprecated. |
Fields declared in class ImageReaderWriterSpi
extraImageMetadataFormatClassNames, extraImageMetadataFormatNames, extraStreamMetadataFormatClassNames, extraStreamMetadataFormatNames, MIMETypes, names, nativeImageMetadataFormatClassName, nativeImageMetadataFormatName, nativeStreamMetadataFormatClassName, nativeStreamMetadataFormatName, pluginClassName, suffixes, supportsStandardImageMetadataFormat, supportsStandardStreamMetadataFormat | Modifier and Type | Field | Description |
|---|---|---|
protected String[] |
extraImageMetadataFormatClassNames |
An array of Strings containing the class names of any additional image metadata formats supported by this plug-in, initially null. |
protected String[] |
extraImageMetadataFormatNames |
An array of Strings containing the names of any additional image metadata formats supported by this plug-in, initially null. |
protected String[] |
extraStreamMetadataFormatClassNames |
An array of Strings containing the class names of any additional stream metadata formats supported by this plug-in, initially null. |
protected String[] |
extraStreamMetadataFormatNames |
An array of Strings containing the names of any additional stream metadata formats supported by this plug-in, initially null. |
protected String[] |
MIMETypes |
An array of strings to be returned from getMIMETypes, initially null. |
protected String[] |
names |
An array of strings to be returned from getFormatNames, initially null. |
protected String |
nativeImageMetadataFormatClassName |
A String containing the class name of the native stream metadata format supported by this plug-in, initially null. |
protected String |
nativeImageMetadataFormatName |
A String containing the name of the native stream metadata format supported by this plug-in, initially null. |
protected String |
nativeStreamMetadataFormatClassName |
A String containing the class name of the native stream metadata format supported by this plug-in, initially null. |
protected String |
nativeStreamMetadataFormatName |
A String containing the name of the native stream metadata format supported by this plug-in, initially null. |
protected String |
pluginClassName |
A String containing the name of the associated plug-in class, initially null. |
protected String[] |
suffixes |
An array of strings to be returned from getFileSuffixes, initially null. |
protected boolean |
supportsStandardImageMetadataFormat |
A boolean indicating whether this plug-in supports the standard metadata format for image metadata, initially false. |
protected boolean |
supportsStandardStreamMetadataFormat |
A boolean indicating whether this plug-in supports the standard metadata format for stream metadata, initially false. |
Fields declared in class IIOServiceProvider
vendorName, version | Modifier and Type | Field | Description |
|---|---|---|
protected String |
vendorName |
A String to be returned from getVendorName, initially null. |
protected String |
version |
A String to be returned from getVersion, initially null. |
Constructor Summary
| Modifier | Constructor | Description |
|---|---|---|
protected |
Constructs a blank ImageWriterSpi. |
|
| Constructs an ImageWriterSpi with a given set of values. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
canEncodeImage |
Returns true if the ImageWriter implementation associated with this service provider is able to encode the given RenderedImage instance. |
abstract boolean |
canEncodeImage |
Returns true if the ImageWriter implementation associated with this service provider is able to encode an image with the given layout. |
ImageWriter |
createWriterInstance() |
Returns an instance of the ImageWriter implementation associated with this service provider. |
abstract ImageWriter |
createWriterInstance |
Returns an instance of the ImageWriter implementation associated with this service provider. |
String[] |
getImageReaderSpiNames() |
Returns an array of Strings containing all the fully qualified names of all the ImageReaderSpi classes that can understand the internal metadata representation used by the ImageWriter associated with this service provider, or null if there are no such ImageReaders specified. |
Class<?>[] |
getOutputTypes() |
Returns an array of Class objects indicating what types of objects may be used as arguments to the writer's setOutput method. |
boolean |
isFormatLossless() |
Returns true if the format that this writer outputs preserves pixel data bit-accurately. |
boolean |
isOwnWriter |
Returns true if the ImageWriter object passed in is an instance of the ImageWriter associated with this service provider. |
Methods declared in class ImageReaderWriterSpi
getExtraImageMetadataFormatNames, getExtraStreamMetadataFormatNames, getFileSuffixes, getFormatNames, getImageMetadataFormat, getMIMETypes, getNativeImageMetadataFormatName, getNativeStreamMetadataFormatName, getPluginClassName, getStreamMetadataFormat, isStandardImageMetadataFormatSupported, isStandardStreamMetadataFormatSupported | Modifier and Type | Method | Description |
|---|---|---|
String[] |
getExtraImageMetadataFormatNames() |
Returns an array of Strings containing the names of additional document formats, other than the native and standard formats, recognized by the getAsTree and setFromTree methods on the image metadata objects produced or consumed by this plug-in. |
String[] |
getExtraStreamMetadataFormatNames() |
Returns an array of Strings containing the names of additional document formats, other than the native and standard formats, recognized by the getAsTree and setFromTree methods on the stream metadata objects produced or consumed by this plug-in. |
String[] |
getFileSuffixes() |
Returns an array of Strings containing a list of file suffixes associated with the formats that are generally usable by the ImageReader or ImageWriter implementation associated with this service provider. |
String[] |
getFormatNames() |
Returns an array of Strings containing human-readable names for the formats that are generally usable by the ImageReader or ImageWriter implementation associated with this service provider. |
IIOMetadataFormat |
getImageMetadataFormat |
Returns an IIOMetadataFormat object describing the given image metadata format, or null if no description is available. |
String[] |
getMIMETypes() |
Returns an array of Strings containing a list of MIME types associated with the formats that are generally usable by the ImageReader or ImageWriter implementation associated with this service provider. |
String |
getNativeImageMetadataFormatName() |
Returns the name of the "native" image metadata format for this plug-in, which typically allows for lossless encoding and transmission of the image metadata stored in the format handled by this plug-in. |
String |
getNativeStreamMetadataFormatName() |
Returns the name of the "native" stream metadata format for this plug-in, which typically allows for lossless encoding and transmission of the stream metadata stored in the format handled by this plug-in. |
String |
getPluginClassName() |
Returns the fully-qualified class name of the ImageReader or ImageWriter plug-in associated with this service provider. |
IIOMetadataFormat |
getStreamMetadataFormat |
Returns an IIOMetadataFormat object describing the given stream metadata format, or null if no description is available. |
boolean |
isStandardImageMetadataFormatSupported() |
Returns true if the standard metadata format is among the document formats recognized by the getAsTree and setFromTree methods on the image metadata objects produced or consumed by this plug-in. |
boolean |
isStandardStreamMetadataFormatSupported() |
Returns true if the standard metadata format is among the document formats recognized by the getAsTree and setFromTree methods on the stream metadata objects produced or consumed by this plug-in. |
Methods declared in class IIOServiceProvider
getDescription, getVendorName, getVersion, onDeregistration, onRegistration | Modifier and Type | Method | Description |
|---|---|---|
abstract String |
getDescription |
Returns a brief, human-readable description of this service provider and its associated implementation. |
String |
getVendorName() |
Returns the name of the vendor responsible for creating this service provider and its associated implementation. |
String |
getVersion() |
Returns a string describing the version number of this service provider and its associated implementation. |
void |
onDeregistration |
A callback that will be whenever the Spi class has been deregistered from a ServiceRegistry. |
void |
onRegistration |
A callback that will be called exactly once after the Spi class has been instantiated and registered in a ServiceRegistry. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Field Details
STANDARD_OUTPUT_TYPE
@Deprecated public static final Class<?>[] STANDARD_OUTPUT_TYPE
{ ImageOutputStream.class }.ImageOutputStream.class, to be returned from getOutputTypes.outputTypes
protected Class<?>[] outputTypes
Class objects to be returned from getOutputTypes, initially null.readerSpiNames
protected String[] readerSpiNames
getImageReaderSpiNames, initially null.Constructor Details
ImageWriterSpi
protected ImageWriterSpi()
ImageWriterSpi. It is up to the subclass to initialize instance variables and/or override method implementations in order to provide working versions of all methods.ImageWriterSpi
public ImageWriterSpi(String vendorName, String version, String[] names, String[] suffixes, String[] MIMETypes, String writerClassName, Class<?>[] outputTypes, String[] readerSpiNames, boolean supportsStandardStreamMetadataFormat, String nativeStreamMetadataFormatName, String nativeStreamMetadataFormatClassName, String[] extraStreamMetadataFormatNames, String[] extraStreamMetadataFormatClassNames, boolean supportsStandardImageMetadataFormat, String nativeImageMetadataFormatName, String nativeImageMetadataFormatClassName, String[] extraImageMetadataFormatNames, String[] extraImageMetadataFormatClassNames)
ImageWriterSpi with a given set of values.- Parameters:
-
vendorName- the vendor name, as a non-nullString. -
version- a version identifier, as a non-nullString. -
names- a non-nullarray ofStrings indicating the format names. At least one entry must be present. -
suffixes- an array ofStrings indicating the common file suffixes. If no suffixes are defined,nullshould be supplied. An array of length 0 will be normalized tonull. -
MIMETypes- an array ofStrings indicating the format's MIME types. If no suffixes are defined,nullshould be supplied. An array of length 0 will be normalized tonull. -
writerClassName- the fully-qualified name of the associatedImageWriterSpiclass, as a non-null String. -
outputTypes- an array ofClassobjects of length at least 1 indicating the legal output types. -
readerSpiNames- an arrayStrings of length at least 1 naming the classes of all associatedImageReaders, ornull. An array of length 0 is normalized tonull. -
supportsStandardStreamMetadataFormat- abooleanthat indicates whether a stream metadata object can use trees described by the standard metadata format. -
nativeStreamMetadataFormatName- aString, ornull, to be returned fromgetNativeStreamMetadataFormatName. -
nativeStreamMetadataFormatClassName- aString, ornull, to be used to instantiate a metadata format object to be returned fromgetNativeStreamMetadataFormat. -
extraStreamMetadataFormatNames- an array ofStrings, ornull, to be returned fromgetExtraStreamMetadataFormatNames. An array of length 0 is normalized tonull. -
extraStreamMetadataFormatClassNames- an array ofStrings, ornull, to be used to instantiate a metadata format object to be returned fromgetStreamMetadataFormat. An array of length 0 is normalized tonull. -
supportsStandardImageMetadataFormat- abooleanthat indicates whether an image metadata object can use trees described by the standard metadata format. -
nativeImageMetadataFormatName- aString, ornull, to be returned fromgetNativeImageMetadataFormatName. -
nativeImageMetadataFormatClassName- aString, ornull, to be used to instantiate a metadata format object to be returned fromgetNativeImageMetadataFormat. -
extraImageMetadataFormatNames- an array ofStrings to be returned fromgetExtraImageMetadataFormatNames. An array of length 0 is normalized tonull. -
extraImageMetadataFormatClassNames- an array ofStrings, ornull, to be used to instantiate a metadata format object to be returned fromgetImageMetadataFormat. An array of length 0 is normalized tonull. - Throws:
-
IllegalArgumentException- ifvendorNameisnull. -
IllegalArgumentException- ifversionisnull. -
IllegalArgumentException- ifnamesisnullor has length 0. -
IllegalArgumentException- ifwriterClassNameisnull. -
IllegalArgumentException- ifoutputTypesisnullor has length 0.
Method Details
isFormatLossless
public boolean isFormatLossless()
true if the format that this writer outputs preserves pixel data bit-accurately. The default implementation returns true.- Returns:
-
trueif the format preserves full pixel accuracy.
getOutputTypes
public Class<?>[] getOutputTypes()
Class objects indicating what types of objects may be used as arguments to the writer's setOutput method. For most writers, which only output to an ImageOutputStream, a single-element array containing ImageOutputStream.class should be returned.
- Returns:
- a non-
nullarray ofClassobjects of length at least 1.
canEncodeImage
public abstract boolean canEncodeImage(ImageTypeSpecifier type)
true if the ImageWriter implementation associated with this service provider is able to encode an image with the given layout. The layout (i.e., the image's SampleModel and ColorModel) is described by an ImageTypeSpecifier object. A return value of true is not an absolute guarantee of successful encoding; the encoding process may still produce errors due to factors such as I/O errors, inconsistent or malformed data structures, etc. The intent is that a reasonable inspection of the basic structure of the image be performed in order to determine if it is within the scope of the encoding format. For example, a service provider for a format that can only encode greyscale would return false if handed an RGB BufferedImage. Similarly, a service provider for a format that can encode 8-bit RGB imagery might refuse to encode an image with an associated alpha channel.
Different ImageWriters, and thus service providers, may choose to be more or less strict. For example, they might accept an image with premultiplied alpha even though it will have to be divided out of each pixel, at some loss of precision, in order to be stored.
- Parameters:
-
type- anImageTypeSpecifierspecifying the layout of the image to be written. - Returns:
-
trueif this writer is likely to be able to encode images with the given layout. - Throws:
-
IllegalArgumentException- iftypeisnull.
canEncodeImage
public boolean canEncodeImage(RenderedImage im)
true if the ImageWriter implementation associated with this service provider is able to encode the given RenderedImage instance. Note that this includes instances of java.awt.image.BufferedImage. See the discussion for canEncodeImage(ImageTypeSpecifier) for information on the semantics of this method.
- Parameters:
-
im- an instance ofRenderedImageto be encoded. - Returns:
-
trueif this writer is likely to be able to encode this image. - Throws:
-
IllegalArgumentException- ifimisnull.
createWriterInstance
public ImageWriter createWriterInstance() throws IOException
ImageWriter implementation associated with this service provider. The returned object will initially be in an initial state as if its reset method had been called. The default implementation simply returns createWriterInstance(null).
- Returns:
- an
ImageWriterinstance. - Throws:
-
IOException- if an error occurs during loading, or initialization of the writer class, or during instantiation or initialization of the writer object.
createWriterInstance
public abstract ImageWriter createWriterInstance(Object extension) throws IOException
ImageWriter implementation associated with this service provider. The returned object will initially be in an initial state as if its reset method had been called. An Object may be supplied to the plug-in at construction time. The nature of the object is entirely plug-in specific.
Typically, a plug-in will implement this method using code such as return new MyImageWriter(this).
- Parameters:
-
extension- a plug-in specific extension object, which may benull. - Returns:
- an
ImageWriterinstance. - Throws:
-
IOException- if the attempt to instantiate the writer fails. -
IllegalArgumentException- if theImageWriter's constructor throws anIllegalArgumentExceptionto indicate that the extension object is unsuitable.
isOwnWriter
public boolean isOwnWriter(ImageWriter writer)
true if the ImageWriter object passed in is an instance of the ImageWriter associated with this service provider.- Parameters:
-
writer- anImageWriterinstance. - Returns:
-
trueifwriteris recognized - Throws:
-
IllegalArgumentException- ifwriterisnull.
getImageReaderSpiNames
public String[] getImageReaderSpiNames()
Strings containing all the fully qualified names of all the ImageReaderSpi classes that can understand the internal metadata representation used by the ImageWriter associated with this service provider, or null if there are no such ImageReaders specified. If a non-null value is returned, it must have non-zero length. The first item in the array must be the name of the service provider for the "preferred" reader, as it will be used to instantiate the ImageReader returned by ImageIO.getImageReader(ImageWriter).
This mechanism may be used to obtain ImageReaders that will generated non-pixel meta-data (see IIOExtraDataInfo) in a structure understood by an ImageWriter. By reading the image and obtaining this data from one of the ImageReaders obtained with this method and passing it on to the ImageWriter, a client program can read an image, modify it in some way, and write it back out preserving all meta-data, without having to understand anything about the internal structure of the meta-data, or even about the image format.
- Returns:
- an array of
Strings of length at least 1 containing names ofImageReaderSpis, ornull. - See Also:
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
{ ImageOutputStream.class }.