1

我通过 Java 中的套接字发送图像,当客户端和服务器都在一台计算机上时一切都很好,但是当我通过 LAN 运行它时,生成的图像是黑色的。我使用 Robot 类拍摄屏幕图像,然后使用 AffineTransform 将其缩小。客户端代码:

        BufferedImage s = null;
        socket = new Socket("AJ-PC", 4444);
        out = new ObjectOutputStream(socket.getOutputStream());
        Robot r = new Robot();
        while(true) {
              s = r.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
              double scale = 0.75;
              int w = (int) (s.getWidth() * scale);
              int h = (int) (s.getHeight() * scale);
              BufferedImage outImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);                
              AffineTransform trans = new AffineTransform();
              trans.scale(scale, scale);
              Graphics2D g = outImage.createGraphics();
              g.drawImage(s, trans, null);
              g.dispose();
              Thread.sleep(400);
              out.writeObject(new SerializableImage(outImage));
       }

服务器代码:

        server = new ServerSocket(4444);
        socket = server.accept();
        System.out.println(socket);
        in = new ObjectInputStream(socket.getInputStream());
        while(running) {
            bi = (SerializableImage) in.readObject();
            b = true;
            System.out.println("new");
            panel.repaint();
        }
4

1 回答 1

0

我正在使用来自http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx的 PsExec 实用程序,这似乎是问题所在。当我不使用它来远程执行时,它运行良好。

于 2012-06-02T19:42:31.777 回答