我正在从图像中获取图像创建日期。我注意到一些图像抛出了Property cannot be found.
错误,而相同的代码在其他图像上工作。
例如,我已经在大约40个图像上测试了我的代码,我没有发现任何问题,但现在我在不同的图像集上测试相同的代码,所有这些图像都抛出了这个错误。
代码:
private DateTime GetDateTakenFromImage(string path)
{
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
using (Image myImage = Image.FromStream(fs, false, false))
{
PropertyItem propItem = myImage.GetPropertyItem(36867);//Throws error here
string dateTaken = new Regex(":").Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2);
return DateTime.Parse(dateTaken);
}
}
我已经检查了工作图像和非工作图像的图像属性,但我看不到任何区别。
这里我漏掉了什么?
发布于 2015-08-14 23:23:01
属性并不总是存在的。首先检查一些类似的东西:
if (myImage.PropertyIdList.Any(p => p == 36867))
https://stackoverflow.com/questions/32013344
复制相似问题