1

I took this function for getting a screenshot from a client application. I to tried adapt this function in my project, but I can not capture desktop showing mouse cursor (coming from a remote pc) in my server application (controller).

Here is my adaptation (in client side) but without success:

void SendScreenProc()
        {
            // Send First Bitmap
            MemoryStream streamScreen = new MemoryStream();
            this.bmpScreenSend = CaptureScreen(true);//new Bitmap(this.boundScreen.Width, this.boundScreen.Height, PixelFormat.Format24bppRgb);
            Graphics g = Graphics.FromImage(this.bmpScreenSend);
            g.CopyFromScreen(0, 0, 0, 0, this.boundScreen.Size);
            this.bmpScreenSend.Save(streamScreen, System.Drawing.Imaging.ImageFormat.Png);
            Compress.CompressStream(streamScreen);
            Byte[] bufferScreen = streamScreen.ToArray();
            mreSendData.WaitOne();
            this.queueSendData.AddScreen(streamScreen.GetBuffer());
            streamScreen.Close();
            this.receivedScreen = 0;

            while (this.remoted)
            {
                // Send next bitmap result by difference with previous bitmap.
                if(this.receivedScreen == 0) {

                } else {
                    Bitmap bmpCurrentScreen = CaptureScreen(true);//new Bitmap(this.boundScreen.Width, this.boundScreen.Height, PixelFormat.Format24bppRgb);
                    g = Graphics.FromImage(bmpCurrentScreen);
                    g.CopyFromScreen(0, 0, 0, 0, this.boundScreen.Size);
                    if (this.receivedScreen == 1) {
                        if(this.bmpScreen != null) {
                            this.bmpScreen.Dispose();
                        }
                        this.bmpScreen = this.bmpScreenSend;
                    } else if(this.receivedScreen == 2) {

                    }
                    if (queueSendData.AvailableScreenAdd && IsDifferent(bmpCurrentScreen, this.bmpScreen))
                    {
                        streamScreen = new MemoryStream();
                        Bitmap bmpDiff = XorBitmap(this.bmpScreen, bmpCurrentScreen);
                        bmpDiff.Save(streamScreen, System.Drawing.Imaging.ImageFormat.Png);
                        this.bmpScreenSend.Dispose();
                        bmpDiff.Dispose();
                        this.bmpScreenSend = bmpCurrentScreen;
                        mreSendData.WaitOne();
                        this.queueSendData.AddScreen(streamScreen.GetBuffer());
                        streamScreen.Close();
                        this.receivedScreen = 0;
                    }
                    else
                    {
                        bmpCurrentScreen.Dispose();
                    }
                }
                Thread.Sleep(30);
            }
        } 
Community
  • 1
  • 1

0 Answers0