java实现简单截图全屏的代码,可以截取全屏并保存到指定位置:
public static void main(String[] args) {
try {
// 获取屏幕尺寸
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// 创建需要截取的矩形区域
Rectangle rect = new Rectangle(0, 0, screenSize.width, screenSize.height);
// 截屏操作
BufferedImage bufImage = new Robot().createScreenCapture(rect);
// 保存截取的图片
ImageIO.write(bufImage, "PNG", new File("d://capture.png"));
} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}