java中ImageIO.write(bufferedImage输出图片时,图片样式的改变调整问题)

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
 
import javax.imageio.ImageIO;
 
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
 
/*
 * 发送客户端截图
 */
class ScreenSpyer extends Thread
{
 
    Socket        socket            = null;
    Robot        robot            = null; // Used to capture screen
    Rectangle    rectangle        = null; // Used to represent screen dimensions
    boolean        continueLoop    = true; // Used to exit the program
    OutputStream out=null;
    ObjectOutputStream oos = null; //对象输出流
    JPEGImageEncoder encoder ;
    public ScreenSpyer(Socket socket, Robot robot, Rectangle rect){
        this.socket = socket;
        this.robot = robot;
        rectangle = rect;
        start();
    }
 
    public void run()
    {
 
        try
        {
            socket.setSendBufferSize(1024);
            //实例化对象
            oos = new ObjectOutputStream(socket.getOutputStream());
            out=socket.getOutputStream();
            encoder=JPEGCodec.createJPEGEncoder(out);
            // 发生客户端屏幕尺寸以计算鼠标所在位置
            oos.writeObject(rectangle);
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
 
        while (continueLoop)
        {       
            //截取客户端屏幕
            BufferedImage image = robot.createScreenCapture(rectangle);
            // 发生客户端截图到服务器
            try
            {
                System.out.println("发送截图之前......");
                ImageIO.write(image, "JPEG", out);
                System.out.println("发送截图之后......");
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
 
            //等待0.1s减小网络阻塞 
            try
            {
                Thread.sleep(100);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
 
    }
 
}

你可能感兴趣的:(java中ImageIO.write(bufferedImage输出图片时,图片样式的改变调整问题))