代码如下
```
package image;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.IOException;
//开始
public class ImageDistinguish {
public static void main(String[] args) throws IOException, AWTException {
Paint p = new Paint();
p.show();
}
//返回屏幕的流
public static BufferedImage imageDistinguish(){
return GetRobot.getRobot().createScreenCapture(new Rectangle(1920, 1080));
}
}
```
//画图
```
package image;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Paint{
JFrame jf = new JFrame();
public Paint() {
}
public void show() {
jf.setSize(1000, 800);
jf.setLocation(300, 100);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setTitle("画布");
jf.add(new MyCavanse());
jf.setResizable(false);
jf.setVisible(true);
}
public static class MyCavanse extends JPanel{
@Override
public void update(Graphics g){ paint(g); }
public void paint(Graphics g) {
g.drawImage(ImageDistinguish.imageDistinguish(), 0, 0, 1000, 800, new ImageObserver() {
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
return false;
}
});
repaint();
}
}
}
```
//单利获取Robot,应该会快一点吧= =
```
package image;
import java.awt.AWTException;
import java.awt.Robot;
public class GetRobot {
private static Robot r = null;
public static Robot getRobot() {
try {
if(r == null)
r = new Robot();
} catch (AWTException e) {
}
return r;
}
}
```
还有如果知道怎么把这个弄成一个视频,知道的花还请大佬告诉一下^_^