简体   繁体   English

仅使用exiftool获取DateTimeOriginal

[英]Only get DateTimeOriginal with exiftool

Hey community, 嘿社区,

Since a few days I'm stuck while trying to get the date of a .jpg or .png image file, when the picture was taken. 几天以来,我一直在尝试获取拍摄照片时的.jpg或.png图像文件的日期。 I believe it was called DateTimeOriginal . 我相信它叫做DateTimeOriginal What I'm trying to do, is getting just this one specific info, DateTimeOriginal , not more, not less. 我正在尝试做的就是获取此特定信息DateTimeOriginal ,而不是更多而不是更少。

This is part of a selfmade project, a program to sort pictures by the date when they were taken. 这是一个自制项目的一部分,该程序可以按拍摄日期对照片进行排序。 I'm programming with VB, and for the exif data I'm calling a batch file. 我正在用VB编程,对于exif数据,我正在调用批处理文件。

So i know how to use the exiftool. 所以我知道如何使用exiftool。 It's common use is: exiftool file.jpg But I need something like: exiftool -DateTimeOriginal file.jpg >> DateTaken.txt I have tried this one, but I'm not getting the Date, I only got a list of any jpg found in the directory, but without metadata. 它的常用用法是: exiftool file.jpg但是我需要类似的东西: exiftool -DateTimeOriginal file.jpg >> DateTaken.txt我已经尝试过了,但是我没有得到Date,我只得到了找到的任何jpg的列表。在目录中,但没有元数据。 I was searching so long for any option like this, but I can't find anything useful. 我一直在寻找类似这样的选项,但是找不到任何有用的东西。 Perhaps there is another, more efficient way to get metadata of an image, only using VB. 也许还有另一种更有效的方式,仅使用VB即可获取图像的元数据。

Has anyone an advise or other idea? 有没有人提供建议或其他想法?

Thanks 谢谢

You have the correct command to get the DateTimeOriginal tag from a file ( exiftool -DateTimeOriginal file.jpg ). 您具有从文件( exiftool -DateTimeOriginal file.jpg )获取DateTimeOriginal标记的正确命令。 But you say you are getting a list of filenames in a directory, which sounds like you're passing a directory name, not a file name. 但是您说要在目录中获取文件名列表,这听起来像是在传递目录名,而不是文件名。 If you wish to get DateTimeOriginal for only those files in a directory that have a value in the tag, use exiftool -if "$DateTimeOriginal" -DateTimeOriginal C:/path/to/dir . 如果只希望为目录中那些在标记中具有值的文件获取DateTimeOriginal ,请使用exiftool -if "$DateTimeOriginal" -DateTimeOriginal C:/path/to/dir Any file that doesn't have a DateTimeOriginal will not be listed then. 然后将不列出任何没有DateTimeOriginal文件。

One thing to note is that the windows "Date Taken" property will be filled by a variety of metadata tags depending upon the filetype. 需要注意的一件事是,窗口“ Date Taken”属性将根据文件类型由各种元数据标签填充。 For example, in PNG files, Windows will use PNG:CreationTime . 例如,在PNG文件中,Windows将使用PNG:CreationTime In jpg files, Windows will use, in order, EXIF:DateTimeOriginal , IPTC:DateCreated + IPTC:TimeCreated , XMP:CreateDate , EXIF:CreateDate , and then XMP:DateTimeOriginal tags. 在jpg文件中,Windows将依次使用EXIF:DateTimeOriginalIPTC:DateCreated + IPTC:TimeCreatedXMP:CreateDateEXIF:CreateDateXMP:DateTimeOriginal标记。

After a bit of digging, I found that you can get a list of properties if a bitmap. 经过一番挖掘,我发现如果有位图,则可以获得属性列表。

Unfortunately the property IDs are numeric and rather cryptic. 不幸的是,属性ID是数字的,而有些含糊。

Have a look here to find out more 在这里看看更多

After a bit more digging, it seems that the propertyId &h132 (a hexadecimal number) is the date stored as an array of integers in ascii encoding. 经过进一步的挖掘后,似乎propertyId&h132(十六进制数字)是以ascii编码形式存储为整数数组的日期。 This function finds propertyid &h132 and returns the date info as a string in year:month:date hour:minute:second format. 此函数查找属性ID&h132,并以字符串形式返回日期信息:year:month:datehour:minute:second。

You might get variations with localization.. for example using / , : or - for the date separators etc, so, to parse it as a date type, you might need to work around that. 你可能会使用得到本地化的变化。例如/:或者-对于日期分隔等,所以,要分析它作为一个日期类型,你可能需要努力解决这一问题。

Public Function GetImageTakenDate(theimage As Bitmap) As String
    Dim propItems As List(Of PropertyItem) = theimage.PropertyItems.ToList
    Dim dt As PropertyItem = propItems.Find(Function(x) x.Id = &H132)
    Dim datestring As String = ""
    For Each ch As Integer In dt.Value
        datestring += Chr(ch)
    Next
    datestring = datestring.Remove(datestring.Length - 1)
    Return datestring
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM