我想捕获流桌面并通过 Java 中的数据报将其发送(到客户端)。以下示例制作屏幕截图。
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;
public class Captura{
static public void captureScreen(String fileName) throws Exception {
Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "png", new File(fileName));
}
//----
public static void main(String[] args) {
try{
System.out.println("[ Captura iniciada ]");
//sleep 5 sg
Thread.currentThread().sleep(5*1000);
String FILENAME="/home/jose/Desktop/captura01.png";
Captura.captureScreen(FILENAME);
System.out.println("[ Captura finalizada ]");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
我是否也必须使用 Robot 类?,我如何发送流?
感谢帮助。
问候!