954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to Capture the screen

The c# code below can be used to capture the screen .
Combined with the filesystemwatcher class ,this code can be used to monitor user activities on a computer.You can also add a timer to this method to capture the screen at regular intervals or you can use a simple client -server application to transfer the captured images to an e-mail account.
In a nutshell u can use this method depending on your needs.
Any corrections or critics corncerning this code is warmly welcomed.

private static Image CaptureScreen()
{
Size s=Screen.PrimaryScreen.Bounds.Size;
 Bitmap bmp=new Bitmap(S.Width,S.height);
Graphics g=Graphics.FromImage(bmp);
g.CopyFromScreen(0,0,0,0,s);
return bmp;
}
EDDYGATE
Newbie Poster
7 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

Looks reasonable, only thing that might be usefulw ould be what if its not the primary screen ?

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

Any corrections or critics corncerning this code is warmly welcomed.

private static Image CaptureScreen()
{
Size s=Screen.PrimaryScreen.Bounds.Size;
 Bitmap bmp=new Bitmap(S.Width,S.height);
Graphics g=Graphics.FromImage(bmp);
g.CopyFromScreen(0,0,0,0,s);
return bmp;
}

i diden't test the code .. but one thing that i see of the top is the use of bitmap in the width , height of the screen. So just stop for a second and think about it.. 1280 x 800, that's my screen resolution , now saved as a 24-bit bitmap it's 3 mb just there... streaming it down the pipe will take some time ... so that's buffering for you... and just then the second screen shot comes along the way ... so that's gonna remain memory resident for a while, and so on and so on.... : MY point is... use jpeg format or resize the bitmap... or you must really have a fast network stream.

miculnegru
Light Poster
33 posts since Nov 2005
Reputation Points: 15
Solved Threads: 5
 

Thanks miculnegru for your correction.
God bless u

EDDYGATE
Newbie Poster
7 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

I am trying to capture a DOS based Qbasic image using the "screen2" command and copy to the clipboard. In all versions of Windows up through 2000, this works by doing "ALT-PRTSCREEN". However, in XP and VISTA it doesn't. The image appears on the screen correctly but you can't copy it to the clipboard. Thanks for any help with this.

stephenca130
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You