2010-07-20 248 views
11

我期待在C#中创建一个非常基本的屏幕共享应用程序。不需要遥控器。我只想让用户能够将他们的屏幕广播到网络服务器。简单的C#屏幕共享应用程序

我该如何实施? (任何指针在正确的方向将不胜感激)。

它不需要高FPS。足以甚至更新5秒左右。你认为只要将截图5秒钟上传到我的Web服务器就足够了吗?

+4

不是我所说的“简单”。 – 2010-07-21 00:00:43

+0

是的,你可以打电话:) – 2016-05-30 20:15:58

回答

11

我以前在博客上写过关于how remote screen sharing software works here的文章,它并不特定于C#,但它对这个主题有了很好的基本理解。该文章中还链接了远程帧缓冲区规范,您可能还需要阅读它。

基本上你会想要截图,你可以传输这些截图并在另一边显示它们。您可以保留最后的屏幕截图,并以块的形式比较屏幕截图,以查看您需要发送哪些屏幕截图。在发送数据之前,您通常会进行某种压缩。

要有遥控器,您可以跟踪鼠标移动并传输它,并在另一端设置指针位置。还有关于击键的内容。只要使用C#进行压缩,您就可以简单地使用JpegBitmapEncoder以您想要的质量创建带有Jpeg压缩的屏幕截图。

JpegBitmapEncoder encoder = new JpegBitmapEncoder(); 
encoder.QualityLevel = 40; 

要比较文件块,您可能最好在旧块和新块上创建一个散列,然后检查它们是否相同。你可以使用任何你想要的hashing algorithm

+0

太棒了!我应该查看哪些内容来比较屏幕截图以及我将要查看的压缩类型? – 2010-07-21 00:19:51

+0

@ user396077:查看我的编辑。 – 2010-07-21 00:28:29

1

嗯,它可以像截图一样简单,压缩它们,然后通过电线发送它们。但是,现有的软件已经这样做了。这是为了练习吗?

2

这里的代码进行屏幕截图,解压缩为位图:

public static Bitmap TakeScreenshot() { 
     Rectangle totalSize = Rectangle.Empty; 

     foreach (Screen s in Screen.AllScreens) 
      totalSize = Rectangle.Union(totalSize, s.Bounds); 

     Bitmap screenShotBMP = new Bitmap(totalSize.Width, totalSize.Height, PixelFormat. 
      Format32bppArgb); 

     Graphics screenShotGraphics = Graphics.FromImage(screenShotBMP); 

     screenShotGraphics.CopyFromScreen(totalSize.X, totalSize.Y, 0, 0, totalSize.Size, 
      CopyPixelOperation.SourceCopy); 

     screenShotGraphics.Dispose(); 

     return screenShotBMP; 
    } 

现在只是将其压缩并发送过来的电线,你就大功告成了。

该代码将多屏幕设置中的所有屏幕合并到一个图像中。根据需要调整。

0

上共享的关键球员/复制的屏幕是一个COM组件调用:RPDViewer enter image description here

该COM组件添加到您的窗口形式和参考文献以及.. 和薄加这段代码到你的窗体加载,您将得到屏幕在您的形式复制:

enter image description here

using RDPCOMAPILib; 
using System; 
using System.Windows.Forms; 

namespace screenSharingAttempt 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     RDPSession x = new RDPSession(); 
     private void Incoming(object Guest) 
     { 
      IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest; 
      MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE; 
     } 


     //access to COM/firewall will prompt 
     private void button1_Click(object sender, EventArgs e) 
     { 
      x.OnAttendeeConnected += Incoming; 
      x.Open(); 
     } 

     //connect 
     private void button2_Click(object sender, EventArgs e) 
     { 
      IRDPSRAPIInvitation Invitation = x.Invitations.CreateInvitation("Trial", "MyGroup", "", 10); 
      textBox1.Text = Invitation.ConnectionString; 
     } 

     //Share screen 

     private void button4_Click(object sender, EventArgs e) 
     { 
      string Invitation = textBox1.Text;// "";// Interaction.InputBox("Insert Invitation ConnectionString", "Attention"); 
      axRDPViewer1.Connect(Invitation, "User1", ""); 
     } 


     //stop sharing 
     private void button5_Click(object sender, EventArgs e) 
     { 
      axRDPViewer1.Disconnect(); 
     } 
    } 
}