在mac OS开发中获取exif数据

时间:2013-08-16 04:23:34

标签: objective-c macos libexif

我是Objective-C的新手,我正试图在我的Mac OS应用程序中获取某些图像的exif数据。看起来我需要一个C库来获取exif数据,所以我搜索了一下,找到了一些C库,但我正在努力实现它们。

1我是否需要获取C库才能读取从DSLR相机拍摄的图像上的exif数据? (就像约会日期一样)

  1. 我尝试了这个图书馆http://libexif.sourceforge.net/,我在网站上挖掘并从这里下载:http://www.hmug.org/pub/MacOS_X/BSD/Libraries/Graphics/libexif/,转到此链接:http://www.hmug.org/pub/MacOS_X/BSD/Libraries/Graphics/libexif/libexif-0.6.21-1-osx8.tar.gz

  2. 我将这些文件用于xcode,看起来文件正确地添加到我的库中,我认为。enter image description here

  3. 我现在不确定如何使用这些C类。我尝试包含这样的文件

    #include "exif-data.h"

    #include "exif-loader.h"

  4. 这是对的吗?我应该采用不同的方式吗?

    1. 然后我对使用感到困惑。在此处的文档页面http://libexif.sourceforge.net/api/上显示
    2.   

      使用libexif的应用程序通常会首先创建一个ExifLoader来将EXIF数据加载到内存中。从那里,它将提取数据作为ExifData开始操作它。每个IFD由ExifData中的自己的ExifContent表示,其中包含ExifEntry形式的所有标记数据。如果需要MakerNote数据,可以从ExifData中提取ExifMnoteData并使用MakerNote函数进行操作。

      “创建ExifLoader”的语法是什么?

      对不起这个菜鸟问题!任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:8)

您可以使用Apples自己的API来获取图片Exif。

这是CGImageSource ReferenceCGimageProperties

她是一个简单的例子:

 NSURL *imageFileURL = [NSURL fileURLWithPath:@"/Users/USERNAME/Documents/tasting_menu_004.jpg"];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL);
NSDictionary *treeDict;
NSMutableString *exifData;


NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache,
                         nil];


CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, ( CFDictionaryRef)options);
CFRelease(imageSource);
if (imageProperties) {
    treeDict = [NSDictionary dictionaryWithDictionary:(NSDictionary*)(imageProperties)];
    id exifTree = [treeDict objectForKey:@"{Exif}"];



    exifData = [NSMutableString stringWithString:@""];



    for (NSString *key in [[exifTree allKeys] sortedArrayUsingSelector:@selector(compare:)])
    {


        NSString* locKey = [[NSBundle bundleWithIdentifier:@"com.apple.ImageIO.framework"] localizedStringForKey:key value:key table: @"CGImageSource"];

        id  value = [exifTree  valueForKey:key]  ;


                   [exifData appendFormat:@"key =%@ ; Value = %@ \n", locKey,value];




    }
 NSLog(@" exifData %@", exifData);

日志 - > exifData

key =光圈值;值= 4.643856

key =色彩空间;值= 65535

key =自定义渲染;值= 0

key =数字化日期时间; Value = 2013:06:13 08:35:07

key =日期时间原件; Value = 2013:06:13 08:35:07

key = Exif版本;价值=(     2,     2,     1 )

key =曝光偏差值;值= 0

key =曝光模式;值= 1

key =曝光计划;值= 1

key =曝光时间;值= 0.0125

key = FNumber;值= 5

key = Flash;值= 9

key = Focal Length;值= 17

key =焦平面分辨率单位;值= 2

key =焦平面X分辨率;值= 3849.211788896504

key =焦平面Y分辨率;值= 3908.141962421712

key = ISO Speed Ratings;价值=(     800 )

key = Max Aperture Value;值= 4

键=计量模式;值= 5

key = Pixel X Dimension;值= 5181

key = Pixel Y Dimension;值= 3454

key =场景捕捉类型;值= 0

key =快门速度值;值= 6.321928

key =主题距离;值= 1.22

key =亚秒级数字化时间;值= 25

key =亚秒时间原始;值= 25

key =白平衡;值= 0

答案 1 :(得分:0)

这篇文章做到了:http://devmacosx.blogspot.com/2011/07/nsimage-exif-metadata.html。我现在可以阅读我正在寻找的所有exif数据。

相关问题