1

我正在尝试保存图像并将其作为电子邮件发送。但是在保存时我得到一个异常,因为 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);
}
4

0 回答 0