我尝试保存图片并将其作为电子邮件发送。但是在保存时我得到一个例外,因为在GDI +中发生了一般性错误。它工作正常,但突然间出现了这个错误。不知道如何继续这个。任何提示和想法将是有益的。在下面分享我的代码:
protected void Button1_Click(object sender, EventArgs e)
{
string path = Server.MapPath(@"images\certi4.jpg");
Bitmap b = new Bitmap(path);
Graphics g = Graphics.FromImage(b);
g.SmoothingMode = SmoothingMode.AntiAlias;
string inputString = TextBox1.Text;
string inputString1 = TextBox2.Text;
string inputString2 = TextBox3.Text;
Font f = new Font("Arial", 15, FontStyle.Bold);
g.DrawString(inputString, f, SystemBrushes.WindowText, new Point(230, 240));
g.DrawString(inputString1, f, SystemBrushes.WindowText, new Point(350, 290));
g.DrawString(inputString2, f, SystemBrushes.WindowText, new Point(250, 377));
Response.Clear();
Response.ContentType = "image/jpeg";
b.Save (Server.MapPath("~/images/certi6.jpg"));//**Error in this part**
b.Save(Response.OutputStream, ImageFormat.Jpeg);
//Server.MapPath("ImageFormat.Jpeg");
MailMessage msg = new MailMessage(txt_From.Text, txt_To.Text);
msg.Subject = txt_Subject.Text;
msg.Body = "<br /><b>From:</b> " + txt_From.Text + "<br /><b>To:</b> " + txt_To.Text + "<br /><br /><br /><br /><b>Name:</b><hr />" + TextBox1.Text + "<br /> <br /><b>Date:</b><br /><hr /><br />" + TextBox2.Text + "<br /><br />";
msg.IsBodyHtml = true;
Attachment objAttachment = new Attachment(Server.MapPath("~/images/certi6.jpg"));
msg.Attachments.Add(objAttachment);
System.Net.Mail.SmtpClient objSmtpClient = new SmtpClient("10.238.52.200", 25);
objSmtpClient.Send(msg);
}