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);
gfxScreen = Graphics.FromImage(bmpScreen);
gfxScreen.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
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