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);
     
    • Constructor Detail

      • PngEncoder

        public PngEncoder​(com.idrsolutions.image.encoder.options.EncoderOptions format)
      • PngEncoder

        public PngEncoder()
    • Method Detail

      • write

        public void write​(BufferedImage image,
                          OutputStream outputStream)
                   throws 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:
        IOException - if the image wasn't written
      • write

        public void write​(BufferedImage image,
                          File file)
                   throws 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:
        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
      • getEncoderOptions

        public com.idrsolutions.image.png.options.PngEncoderOptions getEncoderOptions()
      • setEncoderOptions

        public void setEncoderOptions​(com.idrsolutions.image.png.options.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);