gpt4 book ai didi

java - 远程电脑截图

转载 作者:行者123 更新时间:2023-12-02 00:44:31 25 4
gpt4 key购买 nike

您好,我正在编写一个为远程计算机拍摄快照的程序。

我已经完成了。

ScreenServer.java。

import java.net.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;

public class ScreenServer {
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
BufferedImage screen;

while (true) {
ServerSocket server = new ServerSocket(6659);
Socket client = server.accept();

Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
screen = robot.createScreenCapture(size);
int[] rgbData = new int[(int) (size.getWidth()*size.getHeight())];
screen.getRGB(0,0, (int) size.getWidth(), (int) size.getHeight(), rgbData, 0, (int) size.getWidth());

OutputStream baseOut = client.getOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baseOut);

ImageIO.write(screen, "png", new File("d:\\orig_screen.png"));
out.writeObject(size);

for (int x = 0; x < rgbData.length; x++) {
out.writeInt(rgbData[x]);
}

out.flush();
server.close();
client.close();
out.close();
baseOut.close();
}
}
}

ScreenClient.java

import java.net.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;

public class ScreenClient {

public static void main(String[] args) throws Exception {
Socket server = new Socket("172.22.6.50",6659);

ObjectInputStream in = new ObjectInputStream(server.getInputStream());

Rectangle size = (Rectangle) in.readObject();

int[] rgbData = new int[(int)(size.getWidth() * size.getHeight())];

for (int x = 0; x < rgbData.length;x++) {
rgbData[x] = in.readInt();
}

in.close();
server.close();

BufferedImage screen = new BufferedImage((int) size.getWidth(), (int) size.getHeight(), BufferedImage.TYPE_INT_ARGB);

screen.setRGB(0,0, (int) size.getWidth(), (int) size.getHeight(), rgbData, 0,(int)size.getWidth());

ImageIO.write(screen, "png", new File("d:\\screen.png"));
}
}

但它无法正常工作。服务器拍摄自己的快照。请提供解决方案。

最佳答案

您正在捕获服务器的屏幕截图。请参阅here寻求帮助。

关于java - 远程电脑截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5373896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com