我从this function获取了从客户端应用程序获取屏幕截图。我尝试在我的项目中调整此功能,但我无法在我的服务器应用程序(控制器)中捕获显示鼠标光标(来自远程PC)的桌面。
这是我的改编(在客户端),但没有成功:
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);
}
}