Tuesday, December 15, 2009

How to take ScreenShot in C#

Here by using this code i try to take the Screen Shot of my desktop and it works same as the print screen button does. Here the parameter filename is use for saving the screen shot image in a specified location.

private static Bitmap bmpScreenshot;

private static Graphics gfxScreenshot;

private void TakeScreenShot(string filename)



            bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

            gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            bmpScreenshot.Save(filename, ImageFormat.Png);

            attachedFile = filename;




No comments:

Post a Comment