I’m a little bit surprised and puzzled. I try to read the property items from an image. Particularly, I’m interested in the “Date Taken”. I have written a procedure that does exactly that. More or less. With some files it works perfectly, but…
I have some files that have a ‘Date Taken’ in the properties (when viewed by Windows Explorer, Windows 7 x64). They differ from the date created, modified and accessed. So I do have a 4th date.
However, if I loop through the property items, it does not show up (on any ID).
When I look for it on the PropertyItem.Id (0x9003 or 36867), i get that the property item does not exist.
My Code to loop through the property items:
for (int i = 0; i < fileNames.Length; i++)
{
FileStream fs = new FileStream(fileNames[i], FileMode.Open, FileAccess.Read);
Image pic = Image.FromStream(fs, false, false);
int t = 0;
foreach (PropertyItem pii in pic.PropertyItems)
{
MessageBox.Show(encoding.GetString(pii.Value, 0, pii.Len - 1) + " - ID: " + t.ToString());
t++;
}
}
The code to read only the “Date Taken” property (I stole from here: http://snipplr.com/view/25074/)
public static DateTime DateTaken(Image getImage)
{
int DateTakenValue = 0x9003; //36867;
if (!getImage.PropertyIdList.Contains(DateTakenValue))
return DateTime.Parse("01-01-2000");
string dateTakenTag = System.Text.Encoding.ASCII.GetString(getImage.GetPropertyItem(DateTakenValue).Value);
string[] parts = dateTakenTag.Split(':', ' ');
int year = int.Parse(parts[0]);
int month = int.Parse(parts[1]);
int day = int.Parse(parts[2]);
int hour = int.Parse(parts[3]);
int minute = int.Parse(parts[4]);
int second = int.Parse(parts[5]);
return new DateTime(year, month, day, hour, minute, second);
}
However, when I change the date taken in the ‘File properties window’ of Windows Explorer, It starts to show up in my program.
So my question is: Where does this “Date Taken” comes from? How can I access it? Could it be that there is another source of information besides the EFIX Data?
Thanks!
you can try something like this if you want to start with some basic coding
// Load an image however you like.
System.Drawing.Image image = new Bitmap(“my-picture.jpg”);