Taking screenshots (screen captures) of user displays in a .NET application is quite straightforward on Windows thanks to the Graphics.CopyFromScreen() method. If you want to take screenshots in your .NET Mono application on Linux or Mac OS X however, you will experience difficulties as System.Drawing implementation is incomplete on Mono.
Another limitation of Graphics.CopyFromScreen() is that you cannot take a screenshot of multiple displays at once.
We have stumbled on these problems when we needed to take screen captures reliably on all three platforms in our time tracking application Screenshot Monitor. So we have created a tiny open source .NET library that allows receiving screenshots of the main or all computer displays under Windows, Linux or Mac OS X (with Mono).
You can add it to your project via NuGet package:
PM> Install-Package Pranas.ScreenshotCapture
Then, you can start taking screenshots like this:
// take screenshot from primary display only Image screen = Pranas.ScreenshotCapture.TakeScreenshot(true); screen.Save("PrimaryDisplay.png");
This library also allows taking screenshots from all of the displays at once with a single call like this:
// take screenshot from all displays at once Image screen = Pranas.ScreenshotCapture.TakeScreenshot(); screen.Save("AllDisplays.png");
You can grab the source code or fork us on GitHub. The library is under MIT license, so basically can be used anywhere. Happy coding!