2012-12-18 65 views
3

我有一個函數可以獲取JPEG格式圖片的日期值。我遇到了NEF Nikon原始格式的問題。在Windows 8中,如果將列添加到Windows資源管理器詳細信息視圖中,我可以看到Date Taken值。獲取NEF格式圖像的日期

執行以下操作時收到的錯誤是「此編解碼器不支持指定的屬性。」

public string GetDate(FileInfo f) 
     { 
      string date; 

      using (FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) 
      { 
       BitmapSource img = BitmapFrame.Create(fs); 
       BitmapMetadata md = (BitmapMetadata)img.Metadata; 
       date = md.DateTaken; 
      } 

      return date; 
     } 

我想,在相似的,所以答案參考,使用BitmapMetadata的GetQuery方法在此article的建議,而是返回了同樣的錯誤,這裏是我使用的代碼:

public string GetDate(FileInfo f) 
     { 
      string date; 

      using (FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) 
      { 
       BitmapSource img = BitmapFrame.Create(fs); 
       BitmapMetadata md = (BitmapMetadata)img.Metadata; 
       object t = Mdata.GetQuery("System.Photo.DateTaken"); 
      } 

      return date; 
     } 

我將這部署到Windows 8 PC,所以我不介意只使用Windows 8或.NET 4.5解決方案。

回答

3

我終於明白了這個問題,我不得不在我的電腦上安裝Nikon NEF Codec。我感到困惑的是,Windows 8能夠顯示NEF圖像並提供EXIF的元數據,例如「取出日期」,開箱即用。我的直覺告訴我,我可以使用Windows或.NET庫,無需安裝編解碼器即可獲得相同的信息。不幸的是我時間緊迫,沒有時間深入下去。

+0

我和你在同一條船上,只是在佳能的一面。 Jpegs很好,但是CR2圖片是問題。 Windows資源管理器獲取DateTaken時沒有任何問題,但在通過WIC嘗試時失敗。 – Adarsha