How do I capture the current screen as an image?

2019-02-03 20:02发布

问题:

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!

回答1:

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);
}


回答2:

Check the Graphics.CopyFromScreen method.