Chụp màn hình máy tính với Java

Published by admin on

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class CaptureScreen {
public static void main(String[] args) throws Exception {

try {
System.out.println(“Doi 1 giay nao…”);
Thread.sleep(1000);
} catch(Exception e) {
System.exit(1);
}

String outFileName = “screen.jpg”;

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize);
Robot robot = new Robot();

BufferedImage image = robot.createScreenCapture(screenRect);

ImageIO.write(image, “jpg”, new File(outFileName));
System.out.println(“Da luu vao file “” + outFileName + “”.”);
}

}