【问题标题】:GDI+ General Error on ScreenShot屏幕截图上的 GDI+ 一般错误
【发布时间】:2010-11-26 23:42:24
【问题描述】:

我的内部 Winform 应用程序有以下异常扩展。我的问题是我在ss.save("C:\\HelpMe.jpg", ImageFormat.Jpeg); 上收到generic GDI+ 错误

不是每次都能正常工作,然后出错。有时它会连续工作几次。

这可能是一个“锁定”问题吗?我还应该注意什么和/或做错了什么。

我这样称呼它-->


catch (Exception ex)
        {
            ex.LogError(HUD.ShellForm);
        }

public static void LogError(this Exception exception, DevExpress.XtraEditors.XtraForm whichForm)
    {
        GetDesktopImage(whichForm);
        SendExceptionMail(exception);

        ExceptionMessageBox box = new ExceptionMessageBox(exception);
        box.Show(whichForm);
    }

    private static void SendExceptionMail(Exception exception)
    {
        SmtpClient smtpClient = new SmtpClient("MailServer");

        MailMessage message = new MailMessage
            {
                From = new MailAddress("MATRIX@anEmail"),
                Subject = "MATRIX Application Error",
                Body = exception.Message
            };

        Attachment attachment = new Attachment(@"C:\\HelpMe.jpg");
        message.Attachments.Add(attachment);

        message.To.Add("Developer@anEmail");
        message.To.Add("HelpDesk@anEmail");
        smtpClient.Send(message);
    }

    ///<summary>
    /// Grabs a screen shot of the App and saves it to the C drive in jpg
    ///</summary>
    private static void GetDesktopImage(DevExpress.XtraEditors.XtraForm whichForm)
    {
        Rectangle bounds = whichForm.Bounds;

        using (Bitmap ss = new Bitmap(bounds.Width, bounds.Height))
        using (Graphics g = Graphics.FromImage(ss))
        {
            g.CopyFromScreen(whichForm.Location, Point.Empty, bounds.Size);
            ss.Save("C:\\HelpMe.jpg", ImageFormat.Jpeg);
        }
    }

【问题讨论】:

    标签: c# winforms exception error-handling screenshot


    【解决方案1】:

    这通常是因为:

    1. 目标目录不存在
    2. 目标文件名已在使用中
    3. 目标文件名其实是一个目录
    4. 用户无权写入目标文件

    ...等等...

    本质上,这通常是由于 GDI 无法创建/写入文件造成的。顺便说一句,在 Vista 中,您没有对 C:\

    的写入权限

    【讨论】:

    • 这是 Win 7,我们所有的用户都是本地管理员(不要射击信使)。另外,如果这是问题所在,我认为我一开始就无法创建文件....
    猜你喜欢
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多