Perform a Screen Capture : Screen « 2D Graphics « C# / C Sharp

Perform a Screen Capture


using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public class DesktopCapture {

    private extern static IntPtr GetDesktopWindow();

    private extern static IntPtr GetDC(IntPtr windowHandle);

    private extern static IntPtr GetCurrentObject(IntPtr hdc,
      ushort objectType);

    private extern static void ReleaseDC( IntPtr hdc );

    const int OBJ_BITMAP = 7;

    public static Bitmap Capture() {
        IntPtr desktopWindow = GetDesktopWindow();
        IntPtr desktopDC = GetDC( desktopWindow );
        IntPtr desktopBitmap = GetCurrentObject(desktopDC, OBJ_BITMAP);
        Bitmap desktopImage = Image.FromHbitmap( desktopBitmap );
        return desktopImage;


Related examples in the same category

1.Get Screen ResolutionGet Screen Resolution
2.Takes a screen shot saves it to the specified directory and returns the full file path