Class PNGEncoder


  • public class PNGEncoder
    extends java.lang.Object
    This class allows to encode BufferedImage into B/W, greyscale or true color PNG image format with maximum compression.
    It also provides complete functionality for capturing full screen, part of screen or single component, encoding and saving captured image info PNG file.
    Version:
    1.0
    Author:
    Adam Sotona
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte BW_MODE
      black and white image mode.
      static byte COLOR_MODE
      full color image mode.
      static byte GREYSCALE_MODE
      grey scale image mode.
    • Constructor Summary

      Constructors 
      Constructor Description
      PNGEncoder​(java.io.OutputStream out)
      public constructor of PNGEncoder class with greyscale mode by default.
      PNGEncoder​(java.io.OutputStream out, byte mode)
      public constructor of PNGEncoder class.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void captureScreen​(java.awt.Component comp, java.lang.String fileName)
      Static method performing one component screen capture into PNG image format file with given fileName.
      static void captureScreen​(java.awt.Component comp, java.lang.String fileName, byte mode)
      Static method performing one component screen capture into PNG image format file with given fileName.
      static void captureScreen​(java.awt.Rectangle rect, java.lang.String fileName)
      Static method performing screen capture into PNG image format file with given fileName.
      static void captureScreen​(java.awt.Rectangle rect, java.lang.String fileName, byte mode)
      Static method performing screen capture into PNG image format file with given fileName.
      static void captureScreen​(java.lang.String fileName)
      Static method performing whole screen capture into PNG image format file with given fileName.
      static void captureScreen​(java.lang.String fileName, byte mode)
      Static method performing whole screen capture into PNG image format file with given fileName.
      void encode​(java.awt.image.BufferedImage image)
      main encoding method (stays blocked till encoding is finished).
      • Methods inherited from class java.lang.Object

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

      • PNGEncoder

        public PNGEncoder​(java.io.OutputStream out)
        public constructor of PNGEncoder class with greyscale mode by default.
        Parameters:
        out - output stream for PNG image format to write into
      • PNGEncoder

        public PNGEncoder​(java.io.OutputStream out,
                          byte mode)
        public constructor of PNGEncoder class.
        Parameters:
        out - output stream for PNG image format to write into
        mode - BW_MODE, GREYSCALE_MODE or COLOR_MODE
    • Method Detail

      • encode

        public void encode​(java.awt.image.BufferedImage image)
                    throws java.io.IOException
        main encoding method (stays blocked till encoding is finished).
        Parameters:
        image - BufferedImage to encode
        Throws:
        java.io.IOException - IOException
      • captureScreen

        public static void captureScreen​(java.awt.Rectangle rect,
                                         java.lang.String fileName)
        Static method performing screen capture into PNG image format file with given fileName.
        Parameters:
        rect - Rectangle of screen to be captured
        fileName - file name for screen capture PNG image file
      • captureScreen

        public static void captureScreen​(java.awt.Rectangle rect,
                                         java.lang.String fileName,
                                         byte mode)
        Static method performing screen capture into PNG image format file with given fileName.
        Parameters:
        rect - Rectangle of screen to be captured
        mode - image color mode
        fileName - file name for screen capture PNG image file
      • captureScreen

        public static void captureScreen​(java.awt.Component comp,
                                         java.lang.String fileName)
        Static method performing one component screen capture into PNG image format file with given fileName.
        Parameters:
        comp - Component to be captured
        fileName - String image target filename
      • captureScreen

        public static void captureScreen​(java.awt.Component comp,
                                         java.lang.String fileName,
                                         byte mode)
        Static method performing one component screen capture into PNG image format file with given fileName.
        Parameters:
        comp - Component to be captured
        fileName - String image target filename
        mode - image color mode
      • captureScreen

        public static void captureScreen​(java.lang.String fileName)
        Static method performing whole screen capture into PNG image format file with given fileName.
        Parameters:
        fileName - String image target filename
      • captureScreen

        public static void captureScreen​(java.lang.String fileName,
                                         byte mode)
        Static method performing whole screen capture into PNG image format file with given fileName.
        Parameters:
        fileName - String image target filename
        mode - image color mode