Class JPEGEncoder

All Implemented Interfaces:
Encoder, AutoCloseable

public final class JPEGEncoder extends AbstractImageIOEncoder implements Encoder
Implementation wrapping the default JDK Image I/O JPEG ImageWriter.
  • Constructor Details

    • JPEGEncoder

      public JPEGEncoder()
  • Method Details

    • addMetadata

      protected void addMetadata(IIOMetadataNode baseTree)

      When an unknown node representing an APPn segment is appended to the markerSegment node per the "Native Metadata Format Tree Structure and Editing" section of JPEG Metadata Format Specification and Usage Notes, the Sun JPEG writer writes that segment before the APP0 segment, producing a corrupt image (that resilient readers can nevertheless still read).

      To avoid that, this method does nothing and an alternative metadata- writing technique involving JPEGEncoder.SegmentInjectingOutputStream is used instead.

      Specified by:
      addMetadata in class AbstractImageIOEncoder
      Parameters:
      baseTree - Tree to embed the metadata into.
    • getLogger

      protected org.slf4j.Logger getLogger()
      Specified by:
      getLogger in class AbstractImageIOEncoder
    • getPreferredIIOImplementations

      protected String[] getPreferredIIOImplementations()
      Description copied from class: AbstractImageIOEncoder
      N.B.: This method returns a list of strings rather than classes because some readers reside under the com.sun package, which is encapsulated in Java 9.
      Specified by:
      getPreferredIIOImplementations in class AbstractImageIOEncoder
      Returns:
      Plugins preferred by the application, in order of most to least preferred, or an empty array if there is no preference.
    • getSupportedFormats

      public Set<Format> getSupportedFormats()
      Specified by:
      getSupportedFormats in interface Encoder
      Returns:
      All formats supported by the instance. Note that the implementation must create the instances from scratch and not obtain them from the format registry, which may be empty at the time this method is invoked.
    • encode

      public void encode(RenderedImage image, OutputStream outputStream) throws IOException
      Writes the given image to the given output stream.
      Specified by:
      encode in interface Encoder
      Parameters:
      image - Image to write.
      outputStream - Stream to write the image to.
      Throws:
      IOException