org.fest.swing.image
Class ScreenshotTaker

java.lang.Object
  extended by org.fest.swing.image.ScreenshotTaker

public class ScreenshotTaker
extends Object

Understands taking screenshots of the desktop and GUI components.

Author:
Alex Ruiz, Yvonne Wang

Field Summary
static String PNG_EXTENSION
          Deprecated. use ImageFileExtensions.PNG instead.
 
Constructor Summary
ScreenshotTaker()
          Creates a new ScreenshotTaker.
 
Method Summary
 void saveComponentAsPng(Component c, String imageFilePath)
          Takes a screenshot of the given Component and saves it as a PNG file.
 void saveDesktopAsPng(String imageFilePath)
          Takes a screenshot of the desktop and saves it as a PNG file.
 void saveImage(BufferedImage image, String filePath)
          Save the given image as a PNG file.
 BufferedImage takeDesktopScreenshot()
          Takes a screenshot of the desktop.
 BufferedImage takeScreenshotOf(Component c)
          Takes a screenshot of the given Component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PNG_EXTENSION

@Deprecated
public static final String PNG_EXTENSION
Deprecated. use ImageFileExtensions.PNG instead.
Extension of the image files containing the screenshots taken by instances of this class (png).

See Also:
Constant Field Values
Constructor Detail

ScreenshotTaker

public ScreenshotTaker()
Creates a new ScreenshotTaker.

Throws:
ImageException - if a AWT Robot (the responsible for taking screenshots) cannot be instantiated.
Method Detail

saveDesktopAsPng

public void saveDesktopAsPng(String imageFilePath)
Takes a screenshot of the desktop and saves it as a PNG file.

Parameters:
imageFilePath - the path of the file to save the screenshot to.
Throws:
ImageException - if the given file path is null or empty.
ImageException - if the given file path does not end with ".png".
ImageException - if the given file path belongs to a non-empty directory.
ImageException - if an I/O error prevents the image from being saved as a file.

takeDesktopScreenshot

public BufferedImage takeDesktopScreenshot()
Takes a screenshot of the desktop.

Returns:
the screenshot of the desktop.
Throws:
SecurityException - if readDisplayPixels permission is not granted.

saveComponentAsPng

public void saveComponentAsPng(Component c,
                               String imageFilePath)
Takes a screenshot of the given Component and saves it as a PNG file.

Parameters:
c - the given component.
imageFilePath - the path of the file to save the screenshot to.
Throws:
ImageException - if the given file path is null or empty.
ImageException - if the given file path does not end with ".png".
ImageException - if the given file path belongs to a non-empty directory.
ImageException - if an I/O error prevents the image from being saved as a file.

takeScreenshotOf

public BufferedImage takeScreenshotOf(Component c)
Takes a screenshot of the given Component.

Parameters:
c - the given component.
Returns:
a screenshot of the given component.
Throws:
SecurityException - if readDisplayPixels permission is not granted.

saveImage

public void saveImage(BufferedImage image,
                      String filePath)
Save the given image as a PNG file.

Parameters:
image - the image to save.
filePath - the path of the file to save the image to.
Throws:
ImageException - if the given file path is null or empty.
ImageException - if the given file path does not end with ".png".
ImageException - if the given file path belongs to a non-empty directory.
ImageException - if an I/O error prevents the image from being saved as a file.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.