Class PngEncoder

  • All Implemented Interfaces:
    com.idrsolutions.image.Encoder

    public class PngEncoder
    extends com.idrsolutions.image.JDeliImage
    implements com.idrsolutions.image.Encoder
    Class writes BufferedImages as Fast deflated Png

    Example 1:

    
     PngEncoder encoder = new PngEncoder();
     encoder.write(image, outputStream);
     

    Example 2 (with 8 bit quantisation compression):

    
     PngEncoder encoder = new PngEncoder();
     encoder.getEncoderOptions().setCompressionFormat(PngCompressionFormat.QUANTISED8BIT);
     encoder.write(image, outputStream);
     
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      PngEncoderOptions getEncoderOptions()  
      boolean isCompressed()
      Deprecated.
      - use getEncoderOptions().getCompressionFormat().equals(PngCompressionFormat.QUANTISED8BIT); Returns whether Deflate compression is enabled in tiff generation.
      boolean isOptimizeBasedOnColors()
      Deprecated.
      - use getEncoderOptions().isOptimizeBasedOnColors();
      void setCompressed​(boolean compress)
      Deprecated.
      - use pngEncoderOptions.setCompressionFormat(PngCompressionFormat pngCompression); setEncoderOptions(pngEncoderOptions);
      void setEncoderOptions​(PngEncoderOptions pngEncoderOptions)  
      void setOptimizeBasedOnColors​(boolean optimizeBasedOnColors)
      Deprecated.
      - use pngEncoderOptions.setOptimizeBasedOnColors(boolean); setEncoderOptions(pngEncoderOptions);
      void write​(java.awt.image.BufferedImage image, java.io.File file)
      Writes BufferedImage as a PNG into a file
      void write​(java.awt.image.BufferedImage image, java.io.OutputStream outputStream)
      Writes BufferedImage as a PNG into an OutputStream
      • Methods inherited from class com.idrsolutions.image.JDeliImage

        optimiseImage
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PngEncoder

        public PngEncoder()
    • Method Detail

      • write

        public void write​(java.awt.image.BufferedImage image,
                          java.io.OutputStream outputStream)
                   throws java.io.IOException
        Writes BufferedImage as a PNG into an OutputStream

        This method does not close the provided OutputStream after the write operation has completed; it is the responsibility of the caller to close the stream.

        Specified by:
        write in interface com.idrsolutions.image.Encoder
        Parameters:
        image - BufferedImage to write
        outputStream - The stream to write the image to
        Throws:
        java.io.IOException - if the image wasn't written
      • write

        public void write​(java.awt.image.BufferedImage image,
                          java.io.File file)
                   throws java.io.IOException
        Writes BufferedImage as a PNG into a file

        Parameters:
        image - BufferedImage to write
        file - The file the image to be written as png
        Throws:
        java.io.IOException - if the image wasn't written
      • isCompressed

        @Deprecated
        public boolean isCompressed()
        Deprecated.
        - use getEncoderOptions().getCompressionFormat().equals(PngCompressionFormat.QUANTISED8BIT); Returns whether Deflate compression is enabled in tiff generation.
        Returns:
        Whether compression is enabled
      • setEncoderOptions

        public void setEncoderOptions​(PngEncoderOptions pngEncoderOptions)
      • setCompressed

        @Deprecated
        public void setCompressed​(boolean compress)
        Deprecated.
        - use pngEncoderOptions.setCompressionFormat(PngCompressionFormat pngCompression); setEncoderOptions(pngEncoderOptions);
        Set true to enable 8 bit quantisation compression in PNG generation
      • isOptimizeBasedOnColors

        @Deprecated
        public boolean isOptimizeBasedOnColors()
        Deprecated.
        - use getEncoderOptions().isOptimizeBasedOnColors();
        Returns:
        Whether compression feature is enabled
      • setOptimizeBasedOnColors

        @Deprecated
        public void setOptimizeBasedOnColors​(boolean optimizeBasedOnColors)
        Deprecated.
        - use pngEncoderOptions.setOptimizeBasedOnColors(boolean); setEncoderOptions(pngEncoderOptions);