[英]Sending screenshot via C#
通过该代码捕获屏幕截图来保存。
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("aaaaa@xxxx.com", "Konu");
msg.Subject = konu;
msg.IsBodyHtml = true;
msg.Body = mesaj;
msg.BodyEncoding = System.Text.Encoding.GetEncoding(1254);
NetworkCredential guvenlikKarti = new NetworkCredential("bbbb@bbbb.com", "*****");
client.Credentials = guvenlikKarti;
client.Port = 587;
client.Host = "smtp.live.com";
client.EnableSsl = true;
client.Send(msg);
我想这样做:如何通过smtp协议直接发送屏幕截图作为电子邮件而不保存?
将位图保存到流。 然后将Stream附加到您的邮件消息。 例:
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");
您需要对64进行编码并创建MIME附件。 看到:
用这个:
using (MemoryStream ms = new MemoryStream())
{
Ekran.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
using (Attachment att = new Attachment(ms, "attach_name"))
{
....
client.Send(msg);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.