Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ScreenShot in 4 Steps

0.00/5 (No votes)
30 Jul 2015 1  
Screenshot using C#

Introduction

hi, i am going to show how to take screenshot in four simple steps.

Using the code

Declare bitmap ad Graphics like below.

private static Bitmap bmpScreen;
private static Graphics gfxScreen;

then write the Following line in the command button

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
             bmpScreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                // Create a graphics object from the bitmap
                gfxScreen = Graphics.FromImage(bmpScreen);
                // Take the screenshot from the upper left corner to the right bottom corner
                gfxScreen.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                // Save the screenshot to the specified path that the user has chosen
                bmpScreen.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
            }

we can chage the pixel format, there are verity of different Format Enumeration are avaliable. check the below link.

https://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat(v=vs.110).aspx 

i have used the code inside the saveas dialog box. it help us to Save the Image in the specified location.

or 

we can specify the location manually like below.

bmpScreen.Save(image location here, ImageFormat.Jpeg);

Have Fun!!!

thanks

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here