Java截图⼩程序源码Java编写的全屏截图⼩程序
st.testUtils;
2
3import java.awt.AWTException;
4import java.awt.Dimension;
5import java.awt.Rectangle;
6import java.awt.Robot;
7import java.awt.Toolkit;
8import java.awt.image.BufferedImage;
9import java.io.File;
10import java.io.IOException;
11
12import javax.imageio.ImageIO;
13
14/**
15 * 显⽰器截图
16*/
17
18public class LightScreen {
有趣的java小程序19
20private static String imageFormat = "png"; // 图像⽂件的格式
21
22private static String filePath = "D:/显⽰器截图/"; // 图像⽂件的⽣成路径
23
24public void snapShot(String format, String fileName) throws IOException, AWTException {
25 Dimension screenSize = DefaultToolkit().getScreenSize();
26 Rectangle screenRectangle = new Rectangle(screenSize);
27 Robot robot = new Robot();
28 BufferedImage image = ateScreenCapture(screenRectangle);
29 ImageIO.write(image, format, new File(fileName));
30 }
31
32public static void main(String[] args) throws IOException, AWTException {
33
34 LightScreen cam = new LightScreen();//
35 String fileName = filePath + "截图." + imageFormat;
36
37 cam.snapShot(imageFormat, fileName);
38
39 }
40 }
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论