ScreenShot in 4 Steps






2.45/5 (8 votes)
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