我正在尝试在java中开发一个Screen Sharing应用程序,下面是捕获屏幕截图的代码
public void run() {
java.awt.image.BufferedImage img = null;
Robot robot = null;
try {
robot = new Robot();
} catch (Exception ex) {
ex.printStackTrace();
}
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle rect = new Rectangle(0, 0, size.width, size.height);
javax.swing.ImageIcon icon = null;
while (true) {
try {
img = robot.createScreenCapture(rect);
icon = new javax.swing.ImageIcon(img);
os.writeObject(icon);
os.flush();
icon = null;
try {
Thread.currentThread().sleep(100);
} catch (Exception e) {
}
} catch (Exception ex) {
break;
}
}
}
但它非常慢,它们的延迟是3-4秒,是否可以使用任何开源API?