屏幕共享应用程序与Socket非常慢

时间:2017-09-22 07:28:33

标签: java java-8 screen-capture

我正在尝试在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?

0 个答案:

没有答案