如何在 dotnet 上以编程方式截取屏幕截图并通过电子邮件发送 [英] How to take a screenshot and send by email programaticly on dotnet
问题描述
背景:
我正在开发一个商业应用程序,在最后阶段我们遇到了一些奇怪的错误,主要是连接和一些边缘用例.
I'm developing a bussiness application, and in the final stages we are encountering some extrange errors, mostly with connection and some edge use cases.
对于这种异常,我们现在提供了一个包含错误详细信息的漂亮对话框,用户可以截取其中的屏幕截图,然后通过电子邮件发送并附上一些备注.
For this kind of exceptions, we now provide a nice dialog with error details, of which the user take a screenshot, and send by email with some remarks.
问题:
我想提供更好的体验,并在同一个对话框中提供一个按钮,点击后会打开 Outlook 并准备电子邮件,附上截图作为附件,可能还有日志文件,然后用户可以添加备注并按发送按钮.
I would like to provide a better experience, and provide a single button in the same dialog, wich uppon click, would open outlook and prepare the email, with a screenshot as attachment and maybe a log file, then the user can add remarks and press the send button.
问题:
如何以编程方式截取此屏幕截图,然后将其作为附件添加到 Outlook 邮件中?
How can I take this screenshot programaticly, and then add it as attachment in a outlook mail?
备注:
应用程序在 Microsoft .Net Framework 2.0、C# 或 VB 中
The app is in Microsoft .Net Framework 2.0, C# or VB
推荐答案
首先,要发送截图,可以使用如下代码:
First of all, to send the screenshot, you can use the following code:
//Will contain screenshot
Bitmap screenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
Graphics screenshotGraphics = Graphics.FromImage(bmpScreenshot);
//Make the screenshot
screenshotGraphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
screenshot.save("a place to temporarily save the file", ImageFormat.Png);
要通过 Outlook 发送邮件,您可以使用此处
To send the mail through outlook, you could use the method described here
这篇关于如何在 dotnet 上以编程方式截取屏幕截图并通过电子邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!