& quot;采取的日期& quot;在Windows资源管理器中的文件详细信息(文件属性)中显示时,未在Image PropertyItems中显示 [英] "Date Taken" not showing up in Image PropertyItems while it shows in file details (file properties) in Windows Explorer

查看:68
本文介绍了& quot;采取的日期& quot;在Windows资源管理器中的文件详细信息(文件属性)中显示时,未在Image PropertyItems中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点惊讶和困惑.我尝试从图像中读取属性项.我特别对拍摄日期"感兴趣.我写了一个程序来做到这一点.或多或少.对于某些文件,它可以完美运行,但是...

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...

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

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.

我的代码遍历属性项:

        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++;
            }
        }

仅读取"Date Taken"属性的代码(我从这里偷走了: http://snipplr.com/view/25074/)

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);
    }

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

However, when I change the date taken in the 'File properties window' of Windows Explorer, It starts to show up in my program.

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

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?

谢谢!

推荐答案

如果您想从一些基本编码开始,可以尝试类似的方法

you can try something like this if you want to start with some basic coding

//随心所欲加载图像.System.Drawing.Image图片=新的Bitmap("my-picture.jpg");

// Load an image however you like. 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 ); 
}

这篇关于&amp; quot;采取的日期&amp; quot;在Windows资源管理器中的文件详细信息(文件属性)中显示时,未在Image PropertyItems中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆