当Image StatusItems显示在Windows资源管理器中的文件详细信息(文件属性)时,"Date Taken"未显示在Image PropertyItems中

Jan*_*olo 2 c# exif image windows-7

我有点惊讶和困惑.我尝试从图像中读取属性项.特别是,我对"拍摄日期"很感兴趣.我写了一个完全正确的程序.或多或少.有些文件可以很好地工作,但......

我有一些文件在属性中有一个'Date Taken'(当Windows资源管理器,Windows 7 x64查看时).它们与创建,修改和访问的日期不同.所以我确实有第4个约会.但是,如果我遍历属性项,它不会显示(在任何ID上).当我在PropertyItem.Id(0x9003或36867)上查找它时,我得到该属性项不存在.

我的代码循环遍历属性项:

        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++;
            }
        }
Run Code Online (Sandbox Code Playgroud)

该代码只读取"Date Taken"属性(我从这里偷走了: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);
    }
Run Code Online (Sandbox Code Playgroud)

但是,当我更改Windows资源管理器的"文件属性窗口"中的日期时,它开始显示在我的程序中.

所以我的问题是:这个"采取日期"来自哪里?我该如何访问它?除了EFIX数据之外还有其他信息来源吗?

谢谢!

Met*_*Man 11

如果你想从一些基本的编码开始,你可以尝试这样的东西

//加载您喜欢的图像.System.Drawing.Image image = new Bitmap("my-picture.jpg");

Referenced from AbbydonKrafts

// Get the Date Created property 
//System.Drawing.Imaging.PropertyItem propertyItem = image.GetPropertyItem( 0x132 );
System.Drawing.Imaging.PropertyItem propertyItem 
         = image.PropertyItems.FirstOrDefault(i => i.Id == 0x132 ); 
if( propItem != null ) 
{ 
  // Extract the property value as a String. 
  System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); 
  string text = encoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1 ); 

  // Parse the date and time. 
  System.Globalization.CultureInfo provider = CultureInfo.InvariantCulture; 
  DateTime dateCreated = DateTime.ParseExact( text, "yyyy:MM:d H:m:s", provider ); 
}
Run Code Online (Sandbox Code Playgroud)