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.setCompressed(true);
     encoder.write(image, outputStream);
     
    • Constructor Detail

      • 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

        public boolean isCompressed()
        Returns whether 8 bit quantisation compression is enabled
        Returns:
        Whether compression is enabled
      • setCompressed

        public void setCompressed​(boolean compress)
        Set true to enable 8 bit quantisation compression in PNG generation
        Parameters:
        compress - If compression should be enabled
      • isOptimizeBasedOnColors

        public boolean isOptimizeBasedOnColors()
      • setOptimizeBasedOnColors

        public void setOptimizeBasedOnColors​(boolean optimizeBasedOnColors)