Screen Image Capture

Description: Captures the virtual screen (for multi-monitor setups) and returns it as an image which you could then save or draw on top of. Requires the System.Drawing and System.Windows.Forms namespaces for SystemInformation object.
Tested Platform: .NET 4.8, Visual Studio 2022, Windows 10
Language: C#
// Returns an image object that is a screenshot of the current virtual screen.

public static System.Drawing.Image CaptureScreenImage()
    int screenWidth = SystemInformation.VirtualScreen.Width;
    int screenHeight = SystemInformation.VirtualScreen.Height;
    int screenLeft = SystemInformation.VirtualScreen.Left;
    int screenTop = SystemInformation.VirtualScreen.Top;

    Bitmap bitmap = new Bitmap(screenWidth, screenHeight);

    Graphics g = Graphics.FromImage(bitmap);
    g.CopyFromScreen(screenLeft, screenTop, 0, 0, new Size(screenWidth, screenHeight));

    return bitmap;

Posted: March 19, 2023

Return to the snippets listing