【发布时间】:2011-07-17 15:51:27
【问题描述】:
我想用 C# 构建一个屏幕共享程序。(使用 TCP)
我在网上搜索了一下,发现最有效的方法是从客户端向服务器发送大量屏幕截图。
关键是 - 我如何将位图压缩为 Jpeg - 在服务器上接收它并再次解压缩为位图(以便我可以在表单中显示它)?
我试过使用 JpegBitmapEncoder 没有运气,这是我的代码:
Bitmap screen = TakeScreenshot();
MemoryStream ms = new MemoryStream();
byte[] Bytes = BmpToBytes_Unsafe(screen);
ms.Write(Bytes, 0, Bytes.Length);
Jpeg = new JpegBitmapEncoder();
Jpeg.Frames.Add(BitmapFrame.Create(ms));
Jpeg.QualityLevel = 40;
Jpeg.Save(ms);
BinaryReader br = new BinaryReader(ms);
SendMessage(br.ReadBytes((int)ms.Length));
它在 Jpeg.Frames.Add(BitmapFrame.Create(ms));No imaging component suitable to complete this operation was found. 处抛出 NotSupportedException
所以我需要一种方法将位图转换为 Jpeg,然后转换为字节 [],然后通过 TCP 发送。
在另一端,做完全相反的事情。有什么建议吗?
谢谢。
【问题讨论】:
-
这实际上是效率最低的方法。查看 RFB(远程帧缓冲区)协议