org.apache.xmlgraphics.image.writer.imageio

## Class ImageIOImageWriter

- java.lang.Object
- - org.apache.xmlgraphics.image.writer.imageio.ImageIOImageWriter

- All Implemented Interfaces:
    java.util.EventListener, javax.imageio.event.IIOWriteWarningListener, ImageWriter
  Direct Known Subclasses:
    ImageIOJPEGImageWriter, ImageIOPNGImageWriter, ImageIOTIFFImageWriter

      public class ImageIOImageWriter
      extends java.lang.Object
      implements ImageWriter, javax.imageio.event.IIOWriteWarningListener

  ImageWriter implementation that uses Image I/O to write images.
  Version:
    $Id$

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ImageIOImageWriter(java.lang.String mime)` Main constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `MultiImageWriter` | `createMultiImageWriter(java.io.OutputStream out)` Creates a MultiImageWriter instance that lets you put multiple pages into a single file if the format supports it.
    `protected javax.imageio.metadata.IIOMetadata` | `createStreamMetadata(javax.imageio.ImageWriter writer, javax.imageio.ImageWriteParam writeParam, ImageWriterParams params)` Creates the stream metadata for image.
    `protected static javax.imageio.metadata.IIOMetadataNode` | `getChildNode(org.w3c.dom.Node n, java.lang.String name)` Returns a specific metadata child node
    `protected javax.imageio.ImageWriteParam` | `getDefaultWriteParam(javax.imageio.ImageWriter iiowriter, java.awt.image.RenderedImage image, ImageWriterParams params)` Returns the default write parameters for encoding the image.
    `java.lang.String` | `getMIMEType()`
    `boolean` | `isFunctional()`
    `boolean` | `supportsMultiImageWriter()`
    `protected javax.imageio.metadata.IIOMetadata` | `updateMetadata(java.awt.image.RenderedImage image, javax.imageio.metadata.IIOMetadata meta, ImageWriterParams params)` Updates the metadata information based on the parameters to this writer.
    `void` | `warningOccurred(javax.imageio.ImageWriter source, int imageIndex, java.lang.String warning)`
    `void` | `writeImage(java.awt.image.RenderedImage image, java.io.OutputStream out)` Encodes an image and writes it to an OutputStream.
    `void` | `writeImage(java.awt.image.RenderedImage image, java.io.OutputStream out, ImageWriterParams params)` Encodes an image and writes it to an OutputStream.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ImageIOImageWriter

          public ImageIOImageWriter(java.lang.String mime)

      Main constructor.
      Parameters:
        `mime` - the MIME type of the image format

  - ### Method Detail

    - #### writeImage

          public void writeImage(java.awt.image.RenderedImage image,
                                 java.io.OutputStream out)
                          throws java.io.IOException

      Encodes an image and writes it to an OutputStream.
      Specified by:
        `writeImage` in interface `ImageWriter`
      Parameters:
        `image` - the image to be encoded
        `out` - the OutputStream to write to
      Throws:
        `java.io.IOException` - In case of an /IO problem

    - #### writeImage

          public void writeImage(java.awt.image.RenderedImage image,
                                 java.io.OutputStream out,
                                 ImageWriterParams params)
                          throws java.io.IOException

      Encodes an image and writes it to an OutputStream.
      Specified by:
        `writeImage` in interface `ImageWriter`
      Parameters:
        `image` - the image to be encoded
        `out` - the OutputStream to write to
        `params` - a parameters object to customize the encoding.
      Throws:
        `java.io.IOException` - In case of an /IO problem

    - #### createStreamMetadata

          protected javax.imageio.metadata.IIOMetadata createStreamMetadata(javax.imageio.ImageWriter writer,
                                                                            javax.imageio.ImageWriteParam writeParam,
                                                                            ImageWriterParams params)

      Creates the stream metadata for image. By default, this method returns null which causes the default stream metadata to be used. Subclasses can override this to supply special stream metadata (see TIFF for an example).
      Parameters:
        `writer` - the image write
        `writeParam` - the ImageIO write parameters
        `params` - the ImageWriter write parameters
      Returns:
        the stream metadata (or null if no special metadata needs to be produced)

    - #### getDefaultWriteParam

          protected javax.imageio.ImageWriteParam getDefaultWriteParam(javax.imageio.ImageWriter iiowriter,
                                                                       java.awt.image.RenderedImage image,
                                                                       ImageWriterParams params)

      Returns the default write parameters for encoding the image.
      Parameters:
        `iiowriter` - The IIO ImageWriter that will be used
        `image` - the image to be encoded
        `params` - the parameters for this writer instance
      Returns:
        the IIO ImageWriteParam instance

    - #### updateMetadata

          protected javax.imageio.metadata.IIOMetadata updateMetadata(java.awt.image.RenderedImage image,
                                                                      javax.imageio.metadata.IIOMetadata meta,
                                                                      ImageWriterParams params)

      Updates the metadata information based on the parameters to this writer.
      Parameters:
        `image` - the current image being rendered
        `meta` - the metadata
        `params` - the parameters
      Returns:
        the updated metadata

    - #### getChildNode

          protected static javax.imageio.metadata.IIOMetadataNode getChildNode(org.w3c.dom.Node n,
                                                                               java.lang.String name)

      Returns a specific metadata child node
      Parameters:
        `n` - the base node
        `name` - the name of the child
      Returns:
        the requested child node

    - #### getMIMEType

          public java.lang.String getMIMEType()

      Specified by:
        `getMIMEType` in interface `ImageWriter`
      Returns:
        the target MIME type supported by this ImageWriter

    - #### isFunctional

          public boolean isFunctional()

      Specified by:
        `isFunctional` in interface `ImageWriter`
      Returns:
        true if the ImageWriter is expected to work properly in the current environment

    - #### warningOccurred

          public void warningOccurred(javax.imageio.ImageWriter source,
                                      int imageIndex,
                                      java.lang.String warning)

      Specified by:
        `warningOccurred` in interface `javax.imageio.event.IIOWriteWarningListener`

    - #### createMultiImageWriter

          public MultiImageWriter createMultiImageWriter(java.io.OutputStream out)
                                                  throws java.io.IOException

      Creates a MultiImageWriter instance that lets you put multiple pages into a single file if the format supports it.
      Specified by:
        `createMultiImageWriter` in interface `ImageWriter`
      Parameters:
        `out` - the OutputStream to write the image to
      Returns:
        the requested MultiImageWriter instance
      Throws:
        `java.io.IOException` - In case of an /IO problem

    - #### supportsMultiImageWriter

          public boolean supportsMultiImageWriter()

      Specified by:
        `supportsMultiImageWriter` in interface `ImageWriter`
      Returns:
        true if the implemented format supports multiple pages in a single file

Copyright 1999-2025 The Apache Software Foundation. All Rights Reserved.