1

我正在尝试创建一个远程桌面式程序,并且目前正在尝试获取远程 PC 上的图像,并将其发送回我的客户端 PC 以更新其图像(这种情况每 2-3 秒发生一次。 )

我目前得到这样的桌面图像:

// Set up a bitmap of the correct size
        Bitmap CapturedImage = new Bitmap((int)SystemInformation.VirtualScreen.Width,
            (int)SystemInformation.VirtualScreen.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb565);

        // Create a graphics object from it
        System.Drawing.Size size = new System.Drawing.Size((int)SystemInformation.VirtualScreen.Width, (int)SystemInformation.VirtualScreen.Height);

        using (Graphics gr = Graphics.FromImage(CapturedImage))
        {
            // copy the entire screen to the bitmap
            gr.CopyFromScreen(0, 0, 0, 0,
                size, CopyPixelOperation.SourceCopy);
        }

        EncodeToJPEG(CapturedImage);

EncodeToJPEG 看起来像这样:

var qualityEncoder = Encoder.Quality;
        var quality = (long)0;
        var ratio = new EncoderParameter(qualityEncoder, quality );
        var codecParams = new EncoderParameters(1);
        codecParams.Param[0] = ratio;
        var jpegCodecInfo = GetEncoder(ImageFormat.Jpeg);
        capturedImage.Save(@"c:\Test.jpg", jpegCodecInfo, codecParams); // Save to JPG

我的问题来自 Save 方法。我想知道是否有办法暂时存储这个 JPG 足够长的时间让我让它通过网络发回,而不是保存到文件中?比如,我可以返回一个压缩 JPG 的 Image 对象吗?或者这是不可能的?

我还听说,出于这些目的,将图像分割成块,检查它们的增量并仅发回更改是更快更新此类图像的最有效方法。如果有人对该部门有任何指示,我将不胜感激。

4

1 回答 1

3

编码器具有 OVERLOAD 名称的方法 Save

要传递的参数是 Stream

您将保存到 MemoryStream 以保存内存块

没有文件 !!

最好的 ,

普拉桑特 :)

于 2012-07-10T14:05:20.150 回答