Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I capture the current screen as an image?

I want to add the ability for the users to capture the current screen in my app and email it. I have a very non-technical user base so I need this to be as simple as possible. I plan to let them click a menu item called Help Me! which will then capture the current Application Screen, hopefully as a jpg or png, and then open Outlook and add the image as an attachment.

I was reading through this post ScreenCapture on Code Project but it is a little old and isn't exactly what I was looking for so I thought I would check if there is a better way of doing this.

How do I get started on this? Is there a library or are the built in capabilities enough?

Thanks!

like image 481
Refracted Paladin Avatar asked Apr 03 '09 18:04

Refracted Paladin


2 Answers

That post you linked is the right approach, they just made it very complex. You would want to use Graphics.CopyFromScreen.

Rectangle bounds = this.Bounds;

using(Bitmap ss = new Bitmap(bounds.Width, bounds.Height))
using(Graphics g = Graphics.FromImage(ss))
{
  g.CopyFromScreen(this.Location, Point.Empty, bounds.Size);
  ss.Save("test.jpg", ImageFormat.Jpeg);
}
like image 120
Samuel Avatar answered Sep 30 '22 10:09

Samuel


Check the Graphics.CopyFromScreen method.

like image 45
Christian C. Salvadó Avatar answered Sep 30 '22 09:09

Christian C. Salvadó