Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import javax.imageio.ImageIO;
- public class ScreenCapture {
- public static void captureScreen(String fileName) throws Exception {
- // Create a Robot instance for capturing screen
- Robot robot = new Robot();
- // Define the area of the screen you want to capture
- Rectangle captureRect = new Rectangle(200, 200, 500, 300); // Capture area
- // Capture the defined part of the screen
- BufferedImage capturedImage = robot.createScreenCapture(captureRect);
- // Save the captured image as a PNG file
- File file = new File(fileName);
- ImageIO.write(capturedImage, "PNG", file);
- System.out.println("A partial screenshot was saved!");
- }
- public static void main(String[] args) {
- try {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement