通过C#发送截图

发布于 2024-12-06 10:22:16 字数 1376 浏览 0 评论 0原文

我通过该代码捕获屏幕截图来保存。

Graphics Grf;
Bitmap Ekran = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppPArgb);
Grf = Graphics.FromImage(Ekran);
Grf.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
Ekran.Save("screen.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

然后将保存的屏幕截图作为电子邮件发送:

SmtpClient client = new SmtpClient();
MailMessage msg = new MailMessage();
msg.To.Add(kime);
if (dosya != null)
{
   Attachment eklenecekdosya = new Attachment(dosya);
   msg.Attachments.Add(eklenecekdosya);
}
msg.From = new MailAddress("[email protected]", "Konu");
msg.Subject = konu;
msg.IsBodyHtml = true;
msg.Body = mesaj;
msg.BodyEncoding = System.Text.Encoding.GetEncoding(1254);
NetworkCredential guvenlikKarti = new  NetworkCredential("[email protected]", "*****");
client.Credentials = guvenlikKarti;
client.Port = 587;
client.Host = "smtp.live.com";
client.EnableSsl = true;
client.Send(msg); 

我想这样做:如何通过 smtp 协议直接将屏幕截图作为电子邮件发送而不保存?

I'm saving by capturing screenshot via that code.

Graphics Grf;
Bitmap Ekran = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppPArgb);
Grf = Graphics.FromImage(Ekran);
Grf.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
Ekran.Save("screen.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

Then send this saved screenshot as e-mail:

SmtpClient client = new SmtpClient();
MailMessage msg = new MailMessage();
msg.To.Add(kime);
if (dosya != null)
{
   Attachment eklenecekdosya = new Attachment(dosya);
   msg.Attachments.Add(eklenecekdosya);
}
msg.From = new MailAddress("[email protected]", "Konu");
msg.Subject = konu;
msg.IsBodyHtml = true;
msg.Body = mesaj;
msg.BodyEncoding = System.Text.Encoding.GetEncoding(1254);
NetworkCredential guvenlikKarti = new  NetworkCredential("[email protected]", "*****");
client.Credentials = guvenlikKarti;
client.Port = 587;
client.Host = "smtp.live.com";
client.EnableSsl = true;
client.Send(msg); 

I want to do this : How can I send a screenshot directly as e-mail via smtp protocol without saving?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半衬遮猫 2024-12-13 10:22:16

将位图保存到流中。然后将流附加到您的邮件消息中。例子:

System.IO.Stream stream = new System.IO.MemoryStream();
Ekran.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.Position = 0;
// later:
Attachment attach = new Attachment(stream, "MyImage.jpg");

Save the Bitmap to a Stream. Then attach the Stream to your mail message. Example:

System.IO.Stream stream = new System.IO.MemoryStream();
Ekran.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.Position = 0;
// later:
Attachment attach = new Attachment(stream, "MyImage.jpg");
漫漫岁月 2024-12-13 10:22:16

使用这个:

using (MemoryStream ms = new MemoryStream())
{
    Ekran.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    using (Attachment att = new Attachment(ms, "attach_name"))
    {
        ....
        client.Send(msg);
    }
}

Use this:

using (MemoryStream ms = new MemoryStream())
{
    Ekran.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    using (Attachment att = new Attachment(ms, "attach_name"))
    {
        ....
        client.Send(msg);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文