2009-09-09 49 views
0

我有以下例外扩展为我的内部Winform应用程序。我的问题是,我得到一个generic GDI+错误ss.save("C:\\HelpMe.jpg", ImageFormat.Jpeg);GDI +在ScreenShot上的一般错误

这不是每一次,因为它会工作,然后出错。有时它会连续工作几次。

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

我把这个像这样 - >


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("[email protected]"), 
       Subject = "MATRIX Application Error", 
       Body = exception.Message 
      }; 

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

     message.To.Add("[email protected]"); 
     message.To.Add("[email protected]"); 
     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); 
     } 
    } 

回答

1

这通常是因为:

  1. 目标目录不存在
  2. 的目标文件名已被使用
  3. 目标文件名实际上是一个目录
  4. 用户不访问写入到目标文件

...等...

从本质上讲,这通常导致由GDI无法创建/写入文件。顺便说一句,在Vista中,你没有写访问C:\

+0

这是赢7,我们所有的用户都是本地管理员(不要射击信使)。另外,如果这是问题,我不认为我能够首先创建文件.... – 2009-09-10 01:42:35

相关问题