Screenshoter: Avoid exception while copy screen when there is no desktop.

This commit is contained in:
2019-11-05 17:33:02 +01:00
parent 4da5466de9
commit 474757af5e

View File

@@ -1,4 +1,5 @@
using System.Drawing; using System;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace VAR.ScreenAutomation.Code namespace VAR.ScreenAutomation.Code
@@ -29,11 +30,15 @@ namespace VAR.ScreenAutomation.Code
bmp = new Bitmap(width ?? 0, height ?? 0); bmp = new Bitmap(width ?? 0, height ?? 0);
} }
try
{
// Draw the screenshot into our bitmap. // Draw the screenshot into our bitmap.
using (Graphics g = Graphics.FromImage(bmp)) using (Graphics g = Graphics.FromImage(bmp))
{ {
g.CopyFromScreen(left ?? 0, top ?? 0, 0, 0, bmp.Size); g.CopyFromScreen(left ?? 0, top ?? 0, 0, 0, bmp.Size);
} }
}
catch (Exception) { /* Nom Nom Nom */}
return bmp; return bmp;
} }
} }