我正在從圖像中獲取圖像創建日期。我注意到,有些圖像會導致我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);
}
}
我已經檢查到的圖像性質的工作和非工作圖像,但我看不出有什麼差別。
我在這裏錯過了什麼?
如果這是jpeg EXIF信息,我會尋找EXIF閱讀代碼。 – weston