Class PngEncoder

java.lang.Object
com.idrsolutions.image.JDeliImage
com.idrsolutions.image.png.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 Details

    • PngEncoder

      public PngEncoder(EncoderOptions format)
    • PngEncoder

      public PngEncoder()
  • Method Details

    • 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 an error occurs when trying to write the image
    • 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 to write the image to
      Throws:
      IOException - if an error occurs when trying to write the image
    • isCompressed

      @Deprecated public boolean isCompressed()
      Deprecated.
      - use getEncoderOptions().getCompressionFormat().equals(PngCompressionFormat.QUANTISED8BIT);
      Returns whether 8 bit quantisation compression is set in PNG generation
      Returns:
      Whether compression is enabled
    • getEncoderOptions

      public PngEncoderOptions getEncoderOptions()
      Specified by:
      getEncoderOptions in interface com.idrsolutions.image.Encoder
    • 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
      Parameters:
      compress - value to determine if compression used
    • 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);
                   
      Parameters:
      optimizeBasedOnColors - value to determine strategy of image optimisation