通过C#发送屏幕截图
发布时间:2020-12-15 04:24:22 所属栏目:百科 来源:网络整理
导读:通过该代码捕获屏幕截图来保存. Graphics Grf;Bitmap Ekran = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,PixelFormat.Format32bppPArgb);Grf = Graphics.FromImage(Ekran);Grf.CopyFromScreen(Screen.PrimaryScreen
通过该代码捕获屏幕截图来保存.
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,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"); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |