有效的方式通过WCF发送图像? [英] Efficient way to send images via WCF?

查看:89
本文介绍了有效的方式通过WCF发送图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写,从无到有,像VNC的自定义遥控应用学习WCF,LINQ和一些其他技术。我心目中有三个主要目标创造它:

I am learning WCF, LINQ and a few other technologies by writing, from scratch, a custom remote control application like VNC. I am creating it with three main goals in mind:


  1. 服务器将提供一个应用程序级(即无缝窗口),而不是完整的桌面访问远程控制。

  2. 客户端可以选择任何数量的在服务器上运行的应用程序和接收他们每个人的图像流。

  3. 客户端可以同时连接到多台服务器。

现在我使用WCF来发送重新presents窗口发送一个字节数组:

Right now I am using WCF to send an array of Bytes that represents the window being sent:

using (var ms = new MemoryStream()) {
    window.GetBitmap().Save(ms, ImageFormat.Jpeg);
    frame.Snapshot = ms.ToArray();
}

GetBitmap实现:

GetBitmap implementation:

var wRectangle = GetRectangle();
var image = new Bitmap(wRectangle.Width, wRectangle.Height);
var gfx = Graphics.FromImage(image);

gfx.CopyFromScreen(wRectangle.Left, wRectangle.Top, 0, 0, wRectangle.Size, CopyPixelOperation.SourceCopy);

return image;

据然后通过WCF发送(TCPBinding,它总是会通过LAN)连接到客户端和重建中的空白窗口的形式,像这样没有边框:

It is then sent via WCF (TCPBinding and it will always be over LAN) to the client and reconstructed in a blank windows form with no border like this:

using (var ms = new MemoryStream(_currentFrame.Snapshot))
{
    BackgroundImage = Image.FromStream(ms);
}

我想使这个过程与带宽排在第三位未来CPU和内存使用率尽可能高效。我的目标有客户端连接到服务器5+每个服务器10+的应用程序。

I would like to make this process as efficient as possible in both CPU and memory usage with bandwidth coming in third place. I am aiming to have the client connect to 5+ servers with 10+ applications per server.

是我现有的方法,最好的方法(同时继续使用这些技术),是有什么我可以做,以改善它?

Is my existing method the best approach (while continuing to use these technologies) and is there anything I can do to improve it?

这是我期待到(但我没有经验)思路:

Ideas that I am looking into (but I have no experience with):


  • 使用一个开源的图形库来捕获和保存图像,而不是.NET解决方案。

  • 保存为PNG或其他图像类型而不是JPG。

  • 每次发送图像增量,而不是一个完整的形象。

  • 尝试和'记录'窗口和创建一个COM pressed视频流,而不是图片快照(MPEG?)。

推荐答案

您应该知道这点:


  • 交通:TCP /二进制消息编码将转移最快的方式图像数据

  • 图像捕捉:你可以依靠的P / Invoke访问您的屏幕数据,因为这可以更快和更大的内存占用。一些例子:捕捉屏幕图像在C#[P / Invoke的] ,的How使用.NET [管理] 并的Capturing~~V使用C#(管理)
  • 截图
  • 您应该前减少图像数据发送;

    • 选择您的图像格式明智的,因为一些格式有本地COM pression(如JPG)

    • 的例子应该是查找图像C#
    • 只发送差异的图像时,可以修剪它,只是发送非空区

    • Transport: TCP/binary message encoding will be fastest way to transfer your image data
    • Image capture: you can rely on P/Invoke to access your screen data, as this can be faster and more memory consuming. Some examples: Capturing the Screen Image in C# [P/Invoke], How to take a screen shot using .NET [Managed] and Capturing screenshots using C# (Managed)
    • You should to reduce your image data before send it;
      • choose your image format wisely, as some formats have native compression (as JPG)
      • an example should be Find differences between images C#
      • sending only diff image, you can crop it and just send non-empty areas

      只是之后的通过所有这些步骤,传球和信纳最终code,你可以下载的 VncSharp源$ C ​​$ C 。它实现 RFB协议(维基百科条目)的图形用户界面远程访问一个简单的协议,因为它工作在framebuffer的水平它是适用于所有窗口系统和应用,包括X11, Windows和Macintosh。RFB是VNC(虚拟网络计算)所使用的协议。

      Just after passing through all this steps and being satisfied with your final code, you can download VncSharp source code. It implements the RFB Protocol (Wikipedia entry), "a simple protocol for remote access to graphical user interfaces. Because it works at the framebuffer level it is applicable to all windowing systems and applications, including X11, Windows and Macintosh. RFB is the protocol used in VNC (Virtual Network Computing)."

      这篇关于有效的方式通过WCF发送图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆