C# GDI+;屏幕截图上的一般错误
我的内部Winform应用程序具有以下例外扩展名。我的问题是,C# GDI+;屏幕截图上的一般错误,c#,winforms,exception,error-handling,screenshot,C#,Winforms,Exception,Error Handling,Screenshot,我的内部Winform应用程序具有以下例外扩展名。我的问题是,ss.save(“C:\\HelpMe.jpg”,ImageFormat.Jpeg”)上出现generic GDI+错误 它不是每次都能工作,然后出错。有时它会连续工作几次 这可能是一个“锁定”问题吗?我还应该看什么和/或我做错了什么 我这样叫它--> public static void LogError(此异常为DevExpress.XtraEditors.XtraForm whichForm) { GetDesktopIma
ss.save(“C:\\HelpMe.jpg”,ImageFormat.Jpeg”)上出现generic GDI+
错误代码>
它不是每次都能工作,然后出错。有时它会连续工作几次
这可能是一个“锁定”问题吗?我还应该看什么和/或我做错了什么
我这样叫它-->
public static void LogError(此异常为DevExpress.XtraEditors.XtraForm whichForm)
{
GetDesktopImage(格式);
发送例外邮件(例外);
ExceptionMessageBox=新的ExceptionMessageBox(异常);
显示(哪种格式);
}
私有静态无效SendExceptionMail(异常)
{
SmtpClient SmtpClient=新的SmtpClient(“邮件服务器”);
MailMessage=新的MailMessage
{
发件人=新的邮件地址(“MATRIX@anEmail"),
Subject=“矩阵应用程序错误”,
Body=exception.Message
};
附件附件=新附件(@“C:\\HelpMe.jpg”);
message.Attachments.Add(附件);
message.To.Add(“Developer@anEmail");
message.To.Add(“HelpDesk@anEmail");
发送(消息);
}
///
///抓取应用程序的屏幕截图并将其保存到jpg中的C驱动器
///
私有静态void GetDesktopImage(DevExpress.XtraEditors.XtraForm whichForm)
{
矩形边界=whichForm.bounds;
使用(位图ss=新位图(bounds.Width、bounds.Height))
使用(Graphics g=Graphics.FromImage(ss))
{
g、 CopyFromScreen(格式.位置,点.空,边界.大小);
保存(“C:\\HelpMe.jpg”,ImageFormat.Jpeg);
}
}
这通常是因为:
目标目录不存在
目标文件名已在使用中
目标文件名实际上是一个目录
用户没有写入目标文件的权限
。。。等等
本质上,这通常是由于GDI无法创建/写入文件造成的。顺便说一句,在Vista中,您没有C:\的写入权限,这是Win 7,我们所有的用户都是本地管理员(不要射击messenger)。而且,如果问题是这样的话,我想我根本无法创建文件。。。。
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);
}
}