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 String
Deprecated.private final Robot
private final ImageFileWriter
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new
.ScreenshotTaker
ScreenshotTaker
(ImageFileWriter writer, RobotFactory robotFactory) -
Method Summary
Modifier and TypeMethodDescriptionprivate static JTextComponent
void
saveComponentAsPng
(Component c, String imageFilePath) Takes a screenshot of the given
and saves it as a PNG file.Component
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.private void
showCaretIfPossible
(JTextComponent textComponent) private static void
showCaretOf
(JTextComponent textComponent) Takes a screenshot of the desktop.private BufferedImage
private static BufferedImage
takeScreenshot
(Robot robot, Rectangle r) Takes a screenshot of the given
.Component
private void
-
Field Details
-
PNG_EXTENSION
Deprecated.use
instead.ImageFileExtensions.PNG
Extension 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 isnull
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
Takes a screenshot of the desktop.- Returns:
- the screenshot of the desktop.
- Throws:
SecurityException
- ifreadDisplayPixels
permission is not granted.
-
saveComponentAsPng
Takes a screenshot of the given
and 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 isnull
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
Takes a screenshot of the given
.Component
- Parameters:
c
- the given component.- Returns:
- a screenshot of the given component.
- Throws:
SecurityException
- ifreadDisplayPixels
permission 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 isnull
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.
-
validate
-
instead.ImageFileExtensions.PNG