我的程序拍摄用户屏幕的照片,当他们使用我的程序时,制作屏幕截图,然后将其发送到服务器。图像将加载大约 1/4 的路径并冻结。
发送截图:
BufferedImage buffimg = robot.createScreenCapture(captureSize);
BufferedImage image = buffimg;
byte[] imageInByte;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
baos.flush();
imageInByte = baos.toByteArray();
baos.close();
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
PrintWriter out = new PrintWriter(socket.getOutputStream());
out.println("!SCREENDATA!");
out.flush();
dos.writeInt(baos.toByteArray().length);
dos.write(baos.toByteArray());
dos.flush();
获取图像:
if (input.startsWith("!SCREENDATA!")) {
System.out.println("reading");
DataInputStream dis = new DataInputStream(socket.getInputStream());
int len = dis.readInt();
System.out.println(len);
byte[] data = new byte[len];
dis.read(data);
InputStream in = new ByteArrayInputStream(data);
Image image = Toolkit.getDefaultToolkit().createImage(data);
v.repaint(image);
}
显示图像:
public void repaint(Image img) {
frame.getContentPane().add(new JLabel(new ImageIcon(img)));
frame.repaint();
frame.pack();
}
如果有人可以帮助我,我将不胜感激!