< prev index next >

core/JemmyAWTInput/src/org/jemmy/image/PNGEncoder.java

Print this page




  27 import java.awt.AWTException;
  28 import java.awt.Rectangle;
  29 import java.awt.Robot;
  30 import java.awt.Toolkit;
  31 
  32 import java.awt.image.BufferedImage;
  33 
  34 import java.io.BufferedOutputStream;
  35 import java.io.ByteArrayOutputStream;
  36 import java.io.File;
  37 import java.io.FileNotFoundException;
  38 import java.io.IOException;
  39 import java.io.FileOutputStream;
  40 import java.io.OutputStream;
  41 
  42 import java.util.zip.CRC32;
  43 import java.util.zip.Deflater;
  44 import java.util.zip.DeflaterOutputStream;
  45 import org.jemmy.control.ScreenArea;
  46 
  47 /** This class allows to encode BufferedImage into B/W, greyscale or true color PNG

  48  * image format with maximum compression.<br>
  49  * It also provides complete functionality for capturing full screen, part of
  50  * screen or single component, encoding and saving captured image info PNG file.
  51  * @author Adam Sotona
  52  * @version 1.0 */

  53 public class PNGEncoder extends Object {
  54 
  55     /** black and white image mode. */
  56     public static final byte BW_MODE = 0;
  57     /** grey scale image mode. */
  58     public static final byte GREYSCALE_MODE = 1;
  59     /** full color image mode. */
  60     public static final byte COLOR_MODE = 2;
  61 
  62     OutputStream out;
  63     CRC32 crc;
  64     byte mode;
  65 
  66     /**
  67      *
  68      * @param file
  69      * @throws java.io.FileNotFoundException
  70      */
  71     public PNGEncoder(File file) throws FileNotFoundException {
  72         this(new FileOutputStream(file));
  73     }
  74     /** public constructor of PNGEncoder class with greyscale mode by default.
  75      * @param out output stream for PNG image format to write into
  76      */
  77     public PNGEncoder(OutputStream out) {
  78         this(out, GREYSCALE_MODE);
  79     }
  80 
  81     /** public constructor of PNGEncoder class.
  82      * @param out output stream for PNG image format to write into
  83      * @param mode BW_MODE, GREYSCALE_MODE or COLOR_MODE
  84      */
  85     public PNGEncoder(OutputStream out, byte mode) {
  86         crc=new CRC32();
  87         this.out = out;
  88         if (mode<0 || mode>2)
  89             throw new IllegalArgumentException("Unknown color mode");
  90         this.mode = mode;




  27 import java.awt.AWTException;
  28 import java.awt.Rectangle;
  29 import java.awt.Robot;
  30 import java.awt.Toolkit;
  31 
  32 import java.awt.image.BufferedImage;
  33 
  34 import java.io.BufferedOutputStream;
  35 import java.io.ByteArrayOutputStream;
  36 import java.io.File;
  37 import java.io.FileNotFoundException;
  38 import java.io.IOException;
  39 import java.io.FileOutputStream;
  40 import java.io.OutputStream;
  41 
  42 import java.util.zip.CRC32;
  43 import java.util.zip.Deflater;
  44 import java.util.zip.DeflaterOutputStream;
  45 import org.jemmy.control.ScreenArea;
  46 
  47 /**
  48  * This class allows to encode BufferedImage into B/W, greyscale or true color PNG
  49  * image format with maximum compression.<br>
  50  * It also provides complete functionality for capturing full screen, part of
  51  * screen or single component, encoding and saving captured image info PNG file.
  52  * @author Adam Sotona
  53  * @version 1.0
  54  */
  55 public class PNGEncoder extends Object {
  56 
  57     /** black and white image mode. */
  58     public static final byte BW_MODE = 0;
  59     /** grey scale image mode. */
  60     public static final byte GREYSCALE_MODE = 1;
  61     /** full color image mode. */
  62     public static final byte COLOR_MODE = 2;
  63 
  64     OutputStream out;
  65     CRC32 crc;
  66     byte mode;
  67 





  68     public PNGEncoder(File file) throws FileNotFoundException {
  69         this(new FileOutputStream(file));
  70     }
  71     /** public constructor of PNGEncoder class with greyscale mode by default.
  72      * @param out output stream for PNG image format to write into
  73      */
  74     public PNGEncoder(OutputStream out) {
  75         this(out, GREYSCALE_MODE);
  76     }
  77 
  78     /** public constructor of PNGEncoder class.
  79      * @param out output stream for PNG image format to write into
  80      * @param mode BW_MODE, GREYSCALE_MODE or COLOR_MODE
  81      */
  82     public PNGEncoder(OutputStream out, byte mode) {
  83         crc=new CRC32();
  84         this.out = out;
  85         if (mode<0 || mode>2)
  86             throw new IllegalArgumentException("Unknown color mode");
  87         this.mode = mode;


< prev index next >