Created
May 16, 2012 16:05
-
-
Save vcsjones/2711667 to your computer and use it in GitHub Desktop.
Capture All Monitors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need a reference to System.Windows.Forms and System.Drawing.