Screen Image Capture

Description: Returns an Image that is the full virtual screen screenshot (for multi-monitor setups). Requires the System.Drawing namespace.
Tested Platform: .NET 4.0, Visual Studio 2010, Windows 7
Language: VB.NET
' Returns an image object that is a screenshot of the current virtual screen.

Public Shared Function CaptureScreenImage() As Image

        ' Get virtual screen dimensions (for multiple monitors)
        Dim screenWidth As Integer = SystemInformation.VirtualScreen.Width
        Dim screenHeight As Integer = SystemInformation.VirtualScreen.Height
        Dim screenTop As Integer = SystemInformation.VirtualScreen.Top
        Dim screenLeft As Integer = SystemInformation.VirtualScreen.Left

        ' Setup a bitmap according to the virtual screen dimensions
        Dim Bitmap As Bitmap = New Bitmap(screenWidth, screenHeight)

        Dim g As Graphics = Graphics.FromImage(Bitmap)
        g.CopyFromScreen(screenLeft, screenTop, 0, 0, New Size(screenWidth, screenHeight))

        Return CType(Bitmap, Image)

End Function

Submitted: January 16, 2013

Return to the snippets listing