Class ImageWriterSpi
- All Implemented Interfaces:
RegisterableService
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
FieldsModifier and TypeFieldDescriptionprotected Class<?>[]An array ofClassobjects to be returned fromgetOutputTypes, initiallynull.protected String[]An array of strings to be returned fromgetImageReaderSpiNames, initiallynull.static final Class<?>[]Deprecated.Fields declared in class javax.imageio.spi.ImageReaderWriterSpi
extraImageMetadataFormatClassNames, extraImageMetadataFormatNames, extraStreamMetadataFormatClassNames, extraStreamMetadataFormatNames, MIMETypes, names, nativeImageMetadataFormatClassName, nativeImageMetadataFormatName, nativeStreamMetadataFormatClassName, nativeStreamMetadataFormatName, pluginClassName, suffixes, supportsStandardImageMetadataFormat, supportsStandardStreamMetadataFormatFields declared in class javax.imageio.spi.IIOServiceProvider
vendorName, version -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a blankImageWriterSpi.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) Constructs anImageWriterSpiwith a given set of values. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif theImageWriterimplementation associated with this service provider is able to encode the givenRenderedImageinstance.abstract booleanReturnstrueif theImageWriterimplementation associated with this service provider is able to encode an image with the given layout.Returns an instance of theImageWriterimplementation associated with this service provider.abstract ImageWritercreateWriterInstance(Object extension) Returns an instance of theImageWriterimplementation associated with this service provider.String[]Returns an array ofStrings containing all the fully qualified names of all theImageReaderSpiclasses that can understand the internal metadata representation used by theImageWriterassociated with this service provider, ornullif there are no suchImageReadersspecified.Class<?>[]Returns an array ofClassobjects indicating what types of objects may be used as arguments to the writer'ssetOutputmethod.booleanReturnstrueif the format that this writer outputs preserves pixel data bit-accurately.booleanisOwnWriter(ImageWriter writer) Returnstrueif theImageWriterobject passed in is an instance of theImageWriterassociated with this service provider.Methods declared in class javax.imageio.spi.ImageReaderWriterSpi
getExtraImageMetadataFormatNames, getExtraStreamMetadataFormatNames, getFileSuffixes, getFormatNames, getImageMetadataFormat, getMIMETypes, getNativeImageMetadataFormatName, getNativeStreamMetadataFormatName, getPluginClassName, getStreamMetadataFormat, isStandardImageMetadataFormatSupported, isStandardStreamMetadataFormatSupportedMethods declared in class javax.imageio.spi.IIOServiceProvider
getDescription, getVendorName, getVersion, onDeregistration, onRegistration
-
Field Details
-
STANDARD_OUTPUT_TYPE
Deprecated.Instead of using this field, directly create the equivalent array{ ImageOutputStream.class }.A single-element array, initially containingImageOutputStream.class, to be returned fromgetOutputTypes. -
outputTypes
An array ofClassobjects to be returned fromgetOutputTypes, initiallynull. -
readerSpiNames
An array of strings to be returned fromgetImageReaderSpiNames, initiallynull.
-
-
Constructor Details
-
ImageWriterSpi
protected ImageWriterSpi()Constructs a blankImageWriterSpi. 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) Constructs anImageWriterSpiwith 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()Returnstrueif the format that this writer outputs preserves pixel data bit-accurately. The default implementation returnstrue.- Returns:
trueif the format preserves full pixel accuracy.
-
getOutputTypes
Returns an array ofClassobjects indicating what types of objects may be used as arguments to the writer'ssetOutputmethod.For most writers, which only output to an
ImageOutputStream, a single-element array containingImageOutputStream.classshould be returned.- Returns:
- a non-
nullarray ofClassobjects of length at least 1.
-
canEncodeImage
Returnstrueif theImageWriterimplementation associated with this service provider is able to encode an image with the given layout. The layout (i.e., the image'sSampleModelandColorModel) is described by anImageTypeSpecifierobject.A return value of
trueis 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 returnfalseif handed an RGBBufferedImage. 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
Returnstrueif theImageWriterimplementation associated with this service provider is able to encode the givenRenderedImageinstance. Note that this includes instances ofjava.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
Returns an instance of theImageWriterimplementation associated with this service provider. The returned object will initially be in an initial state as if itsresetmethod 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
Returns an instance of theImageWriterimplementation associated with this service provider. The returned object will initially be in an initial state as if itsresetmethod had been called.An
Objectmay 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
Returnstrueif theImageWriterobject passed in is an instance of theImageWriterassociated with this service provider.- Parameters:
writer- anImageWriterinstance.- Returns:
trueifwriteris recognized- Throws:
IllegalArgumentException- ifwriterisnull.
-
getImageReaderSpiNames
Returns an array ofStrings containing all the fully qualified names of all theImageReaderSpiclasses that can understand the internal metadata representation used by theImageWriterassociated with this service provider, ornullif there are no suchImageReadersspecified. If a non-nullvalue 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
ImageReaderreturned byImageIO.getImageReader(ImageWriter).This mechanism may be used to obtain
ImageReadersthat will generated non-pixel meta-data (seeIIOExtraDataInfo) in a structure understood by anImageWriter. By reading the image and obtaining this data from one of theImageReadersobtained with this method and passing it on to theImageWriter, 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:
-
{ ImageOutputStream.class }.