Skip to content

Instantly share code, notes, and snippets.

@vcsjones
Created May 16, 2012 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcsjones/2711667 to your computer and use it in GitHub Desktop.
Save vcsjones/2711667 to your computer and use it in GitHub Desktop.
Capture All Monitors
[STAThread]
static void Main()
{
var size = Screen.AllScreens.Aggregate(Size.Empty, (sz, screen) =>
{
var boundHeight = screen.Bounds.Y + screen.Bounds.Height;
var boundWidth = screen.Bounds.X + screen.Bounds.Width;
return new Size(boundWidth > sz.Width? boundWidth : sz.Width, boundHeight > sz.Height? boundHeight : sz.Height);
});
using (var bitmap = new Bitmap(size.Width, size.Height))
{
using (var graphics = Graphics.FromImage(bitmap))
{
foreach (var screen in Screen.AllScreens)
{
graphics.CopyFromScreen(screen.Bounds.Location, screen.Bounds.Location, screen.Bounds.Size);
}
}
using (var fileStream = new FileStream("C:\\foo.png", FileMode.Create))
{
bitmap.Save(fileStream, ImageFormat.Png);
}
}
}
@vcsjones
Copy link
Author

Need a reference to System.Windows.Forms and System.Drawing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment