How to take ScreenShot in C#

To create a screenshot in c# we need to use drawing api of the .net framework

First you have import System.Drawing.Imaging name space with following code...

using System.Drawing.Imaging;

here is the code in C# for screenshot.

int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));

bmpScreenShot.Save("test.jpg", ImageFormat.Jpeg);

Published Monday, January 28, 2008 8:04 PM by Jalpesh P. Vadgama
Filed under:

Comments

# re: How to take ScreenShot in C#

Friday, April 4, 2008 2:32 AM by Punkster812

This was exactly what I was looking for, thank you so much. It is great to share knowledge like this.

# re: How to take ScreenShot in C#

Saturday, July 12, 2008 1:08 PM by Tuskan360

finaly, someone has shown me a simple, easy way to do this.  It worked straight off and is a huge improvement on some of the other long winded methods of doing this I've seen

# re: How to take ScreenShot in C#

Friday, May 1, 2009 5:49 AM by HarriedProgrammer

Thanks a lot for the info.  Exactly what I needed.

# re: How to take ScreenShot in C#

Monday, May 18, 2009 6:56 AM by Debabrata Dutta

really Very good example which is really works fine a lot of Thanks

# re: How to take ScreenShot in C#

Monday, June 15, 2009 4:23 PM by Ramie

Where does it save to?

# re: How to take ScreenShot in C#

Wednesday, July 8, 2009 3:05 AM by Edwin

Thanks Mr.Jalpesh P. Vadgama

         Really very useful code.

# re: How to take ScreenShot in C#

Thursday, August 20, 2009 2:51 AM by Codehunter

Thanks a lot sir

was looking for a code like this !!!!!

# re: How to take ScreenShot in C#

Friday, June 24, 2011 2:50 PM by cowtheboy

where should we add the ocde sample? can we do it in a button click event?

# re: How to take ScreenShot in C#

Saturday, June 25, 2011 9:40 AM by Jalpesh P. Vadgama

@Cowtheboy- You can do it any where you want.

# re: How to take ScreenShot in C#

Tuesday, August 23, 2011 3:00 AM by Ramesh

The code is not working in VS.Net 2010

Can i get the equivalent code for WPF 2010

# re: How to take ScreenShot in C#

Saturday, April 28, 2012 1:24 AM by ashraf

may you help to use it in asp.net???

# re: How to take ScreenShot in C#

Thursday, May 3, 2012 3:38 PM by Jalpesh P. Vadgama

@ashraf - its not possible to use this in asp.net