如何从我的 jpeg 中获取 EXIF 数据?
我必须将日期和名称链接到我包含在捆绑包中的某些 jpeg,或者可能从我自己的服务器下载到“文档”文件夹。有没有办法轻松提取 EXIF 数据?
如果是这样,那么我将使用 EXIF 来存储此信息。如果没有,那么我将不得不创建一个数据库或平面文件,将我的额外数据映射到图像文件。
请记住,这些不是 iPhone 拍摄的照片,也不是通过 UIImagePicker 或从沙箱外部提供的照片。这些是我在应用程序中包含的照片或我自己下载到“文档”文件夹中的照片。这里重要的一点是简单:
是否更容易,
- 从我的图像文件中读取 EXIF 文件
- 有另一个文件可以跟踪 图像文件和相关的 数据(可以是sqlite)
谢谢!
I have to link a date and a name to some jpegs that I am including in my bundle, or possibly downloading from my own server to the Documents folder. Is there a way to extract EXIF data easily?
If so, then I will use EXIF to store this info. If not, then I will have to create a database or flat file that maps my extra data to the image file.
Keep in mind, these are not photos the iPhone has taken and is providing via UIImagePicker or from outside the sandbox. These are photos that I am including with the app or downloadig to the Docs folder myself. The important point here is ease:
Is it easier to
- read EXIF file from my image files
- have another file that keeps track of
the image file and the associated
data (could be sqlite)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试使用 iphone-exif 工具包提取数据。但是,它是 GPL 许可的,如果您的应用程序是商业应用,则需要协商许可协议。如果这不可行,那么您可能需要采用外部元数据路线。
You can try using iphone-exif toolkit to extract the data. However, it's licensed GPL and if your app is commercial you'll need to negotiate a license deal. If that's not viable then you may want to go the external meta-data route.
实际的 EXIF 数据以一个小的 TIFF 文件,带有 EXIF 特定的 TIFF 标记,用于在 TIFF 中没有归属的信息规格。当放入 JPEG 文件(实际上是 JFIF 比特流)中时,它存储在 JPEG APP1 标记中,该标记将 EXIF 数据的总大小限制为略小于 64KB。
找到 APP1 标记,确认它包含 EXIF 数据,然后使用相当强力的编码解析出特定的 EXIF 标签集合,应该不会那么困难。
您可以查看的一个示例是 exiftool ,它就是这样做的,并且是用 Perl 编写的,并且按照与 Perl 本身相同的条款开源。
The actual EXIF data is stored in the form of a small TIFF file with EXIF-specific TIFF tags for information that doesn't have a home in the TIFF specification. When placed in a JPEG file (really a JFIF bitstream), it is stored in a JPEG APP1 marker which limits the total size of the EXIF data to just a bit less than 64KB.
It shouldn't be that difficult to locate the APP1 marker, confirm it contains EXIF data, and then parse out a specific collection of EXIF tags with fairly brute force coding.
One example you can look at is exiftool which does just that, and is written in Perl and open source under the same terms as Perl itself.
如果这些文件纯粹用于您自己的应用程序,并且不会被用户在其他工具中重用,那么将您的数据以 XML/JSON 形式存储在注释段 0xFFFE 中是有一定作用的。正如之前提到的,您可以使用的内存还差 64k。
使用注释段的好处在于它应该由图像编辑工具保存,可以快速访问(因为您不需要遍历存储EXIF数据的IFD块,您只需读/写4字节类型的文本字符串/length header)并且在图形应用程序中是人类可读/可写的。
如果可行的话,我会避免将关联的数据存储在数据库中,这样您就不会冒数据库与可用文件不同步的风险。
If these files are purely for use in your own application and will not be reused in other tools by the user, then there is some mileage in storing your data as XML/JSON in the comment segment 0xFFFE. As mentioned before you get just short of 64k to play with.
The beauty of using the comment segment is that it should be preserved by image editing tools, is quick to access (because you do not need to traverse the IFD blocks that store EXIF data, you just read/write a text string with 4 byte type/length header) and is human readable/writable in a graphics app.
I would avoid storing the associated data in a db if practical, so that you don't risk the db becoming out of sync with the available files.
我使用
嵌入在我的应用程序中的 ExifTool 。工作是一种享受。
I use ExifTool
embedded in my app. Works a treat.