I have a function that gets the date taken value for pictures in JPEG format. I’ve run into a problem with the NEF Nikon raw format. In Windows 8 I can see the Date Taken value if I add the column to the Windows Explorer detail view.
The error I receive when the following is executed is “This codec does not support the specified property.”
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;
}
I tried the suggestion in this article that is referenced in similar SO answers, using the GetQuery method for BitmapMetadata, but that returned the same error, here was the code I used:
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;
}
I’m deploying this to a Windows 8 PC, so I don’t mind a Windows 8 or .NET 4.5 only solution.
I finally figured out the issue, I had to install the Nikon NEF Codec on my PC. What I’m confused about is that Windows 8 is able to display NEF images and provide metadata from EXIF such as Date Taken, out of the box. My gut tells me that there is a Windows or .NET library I could use that I could obtain the same information without installing the codec. Unfortunately I’m pressed for time and don’t have time to dive deeper.