gpt4 book ai didi

c# - ScreenShot上的GDI +一般错误

转载 作者:行者123 更新时间:2023-12-03 08:36:33 25 4
gpt4 key购买 nike

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

并非每次都能工作,然后出错。有时它会连续运行几次。

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

我这样称呼->

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);
}
}

最佳答案

这通常是因为:

  • 目标目录不存在
  • 目标文件名已在使用中
  • 目标文件名实际上是一个目录
  • 用户无权写入目标文件

  • ...等等...

    本质上,这通常是由GDI无法创建/写入文件引起的。顺便说一句,在Vista中,您无权访问C:\

    关于c# - ScreenShot上的GDI +一般错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1402066/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com