微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我以随机频率收到“GDI+ 中发生一般错误在 System.Drawing.Image.Save”?

如何解决为什么我以随机频率收到“GDI+ 中发生一般错误在 System.Drawing.Image.Save”?

这是我的基本代码

#region privateMethods
private bool SaveImageFile(string absolutePathFile,byte[] file,ImageFormat format)
{
    try
    {
        string directoryPath = Path.GetDirectoryName(absolutePathFile);
        if (!Directory.Exists(directoryPath)) Directory.CreateDirectory(directoryPath);
        if (File.Exists(absolutePathFile)) File.Delete(absolutePathFile);

        using (MemoryStream ms = new MemoryStream(file))
        using (var bmp = Image.FromStream(ms))     
            bmp.Save(absolutePathFile,format);

        return true;

    }
    catch (ArgumentException argEx)
    {
        EventLogger.WriteLog("UploadImageFile: This file it isn't an image " + argEx.Message,System.Diagnostics.EventLogEntryType.Error);
    }
    catch (Exception ex)
    {
        EventLogger.WriteLog("UploadImageFile: " + ex.Message + " " + ex.StackTrace + "PathFile: " + absolutePathFile,System.Diagnostics.EventLogEntryType.Error);
    }
    return false;
}

这看起来很基础。哪个可能是原因?或者我怎样才能更好地进行调查?

这似乎并不总是发生,而是“有时”。这真的很奇怪并且在控制之下,发生的随机性......

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。