我写的程序需要把客户机的屏幕截取,再发送到服务器。我用下面一段代码实现了截取屏幕:BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle(0, 0, (int) d.getWidth(), (int) d.getHeight()));
现在想把 BufferedImage 对象用 DataOutputStream 发送出去,但不知道怎么把BufferedImage变成字节流!谢谢~~~~
现在想把 BufferedImage 对象用 DataOutputStream 发送出去,但不知道怎么把BufferedImage变成字节流!谢谢~~~~
ImageIcon imageIcon = new ImageIcon( screenshot );
//将你的BufferedImage screenshot 对象变成可通过网络传输的ImageIcon对象 OutputStream os = yoursocket.getOutputStream();
//获取网络输出流 ObjectOutputStream oos = new ObjectOutputStream( os );
//转成对象输出流oos.writeObject( imageIcon );
//发送图像 oos.flush();
//及时刷新一下