How to

create screenshot using C#

Published: 13. December 2008 | Updated: 20. December 2008
License: Microsoft Public License (MS-PL)
Categories: GDI, Windows
Tags: C# GDI Windows
Was this snippet helpful for you? YESYES / NONO

Method for creating bitmap with screenshot

Code

public static Bitmap CreateScreenshot()
{
    // create bitmap
    Bitmap res = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                            Screen.PrimaryScreen.Bounds.Height,
                            PixelFormat.Format32bppArgb);

    // create graphics
    Graphics g = Graphics.FromImage(res);

    // capture screen
    g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0,
                        Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

    return res;
}
Send us feedback about this snippet »



Related Snippets: