c# - 为什么我以随机频率收到此“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;
}
这似乎很基本。哪个可能是原因?或者我怎样才能更好地调查?
它似乎并不总是发生,而是“有时”发生。这真的很奇怪,并且在控制之下,发生的随机性......
解决方案
推荐阅读
- javascript - 如何触发 JQuery 选项卡元素的点击事件
- r - 按多个组计算跨多个列的最大值
- routing - 具有 Istio Ingress 的 Kubernetes 未在标准 HTTP 端口 443/80 上运行
- php - Laravel Guzzle GET 请求
- vba - 编写循环以将底部 20 行的值设置为 0
- android - 如何通过opencv实时检测人脸?
- javascript - 用于显示修改为与多个唯一 div 一起使用的 div 的 javascript 代码
- javascript - 静态只读成员赋值 => TypeError: XXX is not a constructor
- java - 重新发送到卡夫卡主题时骆驼的无限循环
- javascript - webpush 通知过期