C# 将映像保存为服务器时,GDI+中出现一般错误。MapPath()

C# 将映像保存为服务器时,GDI+中出现一般错误。MapPath(),c#,asp.net,image,exception-handling,jpeg,C#,Asp.net,Image,Exception Handling,Jpeg,我正在尝试保存图像并将其作为电子邮件发送。但在保存时,我得到了一个异常,因为GDI+中发生了一般错误。它工作得很好,但突然出现了这个错误。不知道该怎么做。任何提示和想法都会很有帮助。在下面共享我的代码: protected void Button1_Click(object sender, EventArgs e) { string path = Server.MapPath(@"images\certi4.jpg"); Bitmap b = new Bitmap(path);

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

我刚刚使用了内存流及其工作方式: