Package org.fest.swing.image
Class ScreenshotTaker
java.lang.Object
org.fest.swing.image.ScreenshotTaker
Understands taking screenshots of the desktop and GUI components.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.private final Robotprivate final ImageFileWriter -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new.ScreenshotTakerScreenshotTaker(ImageFileWriter writer, RobotFactory robotFactory) -
Method Summary
Modifier and TypeMethodDescriptionprivate static JTextComponentvoidsaveComponentAsPng(Component c, String imageFilePath) Takes a screenshot of the givenand saves it as a PNG file.ComponentvoidsaveDesktopAsPng(String imageFilePath) Takes a screenshot of the desktop and saves it as a PNG file.voidsaveImage(BufferedImage image, String filePath) Save the given image as a PNG file.private voidshowCaretIfPossible(JTextComponent textComponent) private static voidshowCaretOf(JTextComponent textComponent) Takes a screenshot of the desktop.private BufferedImageprivate static BufferedImagetakeScreenshot(Robot robot, Rectangle r) Takes a screenshot of the given.Componentprivate void
-
Field Details
-
PNG_EXTENSION
Deprecated.useinstead.ImageFileExtensions.PNGExtension of the image files containing the screenshots taken by instances of this class (png).- See Also:
-
robot
-
writer
-
-
Constructor Details
-
ScreenshotTaker
public ScreenshotTaker()Creates a new.ScreenshotTaker- Throws:
ImageException- if a AWT Robot (the responsible for taking screenshots) cannot be instantiated.
-
ScreenshotTaker
ScreenshotTaker(ImageFileWriter writer, RobotFactory robotFactory)
-
-
Method Details
-
saveDesktopAsPng
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 isnullor 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
Takes a screenshot of the desktop.- Returns:
- the screenshot of the desktop.
- Throws:
SecurityException- ifreadDisplayPixelspermission is not granted.
-
saveComponentAsPng
Takes a screenshot of the givenand saves it as a PNG file.Component- Parameters:
c- the given component.imageFilePath- the path of the file to save the screenshot to.- Throws:
ImageException- if the given file path isnullor 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
Takes a screenshot of the given.Component- Parameters:
c- the given component.- Returns:
- a screenshot of the given component.
- Throws:
SecurityException- ifreadDisplayPixelspermission is not granted.
-
takeScreenshot
-
findFocusOwnerAndHideItsCaret
-
takeScreenshot
-
showCaretIfPossible
-
showCaretOf
-
saveImage
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 isnullor 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.
-
validate
-
instead.ImageFileExtensions.PNG