简体   繁体   English

如何将当前屏幕捕获为图像?

[英]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! 我打算让他们点击一个名为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. 然后将捕获当前的应用程序屏幕,希望作为jpg或png,然后打开Outlook并将图像添加为附件。

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. 我正在阅读这篇关于Code Project的ScreenCapture帖子,但它有点老了,并不是我想要的所以我想我会检查是否有更好的方法来做到这一点。

How do I get started on this? 我该如何开始这个? Is there a library or are the built in capabilities enough? 是否有图书馆或内置功能足够?

Thanks! 谢谢!

That post you linked is the right approach, they just made it very complex. 你链接的帖子是正确的方法,他们只是使它非常复杂。 You would want to use Graphics.CopyFromScreen . 您可能希望使用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);
}

检查Graphics.CopyFromScreen方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM