2010-08-09 47 views
6

我有以下C#代碼,我正在使用它捕獲遠程桌面(RDP)會話中的屏幕截圖。它會在會話處於活動狀態時正常工作,但如果我將會話最小化,則會導致無效句柄異常。捕獲最小化遠程桌面的屏幕截圖

有什麼辦法可以做到這一點,或者當會話最小化時屏幕基本上「消失」了嗎?

string filename = @"C:\Snap.png"; 
Size bitmapSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); 
using (Bitmap bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height, PixelFormat.Format24bppRgb)) 
using (Graphics graphics = Graphics.FromImage(bitmap)) 
{ 
    graphics.CopyFromScreen(// Exception thrown here 
     new Point(0, 0), 
     new Point(0, 0), 
     bitmapSize); 
    bitmap.Save(filename, ImageFormat.Png); 
} 
+0

程序是在遠程機器還是本地機器上運行? – siride 2010-08-09 05:06:18

+0

它在遠程機器上運行。 – ngoozeff 2010-08-09 05:16:05

回答

4

您必須臨時恢復窗口,捕獲並再次將其最小化。 This link shows how to do it silently

+0

如果我在客戶端截取屏幕截圖,這將起作用。我寧願在遠程會話中使用某些東西,但如果沒有其他的東西出現,我會繼續使用它。 – ngoozeff 2010-08-09 06:00:02