2013-08-16 13 views
1

我是Objective-C的新品牌,我試圖在Mac OS應用程序的某些圖像上獲取exif數據。它看起來像我需要一個C庫來獲取exif數據,所以我搜索了一下,並找到了一些C庫,但我正在努力如何實現它們。在mac OS開發中獲取exif數據

1我是否需要獲取C庫才能讀取從數碼單反相機拍攝的圖像上的exif數據? (如日期事情采取)

  • 我想這個庫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

  • 我將這些文件吸收到xcode中,我認爲它看起來像文件被正確添加到我的庫中。 enter image description here

  • 我不確定現在如何使用這些C類。我試着包括這樣

    #include "exif-data.h"

    #include "exif-loader.h"

  • 這是正確的文件嗎?我應該以不同的方式去做嗎?

    1. 然後我對使用情況非常困惑。在文檔頁面在這裏http://libexif.sourceforge.net/api/它使用libexif通常會先創建一個ExifLoader到EXIF數據加載到內存中說

    的應用程序。從那裏,它會將這些數據提取爲ExifData以開始操作它。每個IFD都由ExifData中的ExifContent表示,其中包含ExifEntry表單中的所有標籤數據。如果MakerNote數據是必需的,則可以從ExifData中提取ExifMnoteData並使用MakerNote函數進行操作。

    「創建ExifLoader」的語法是什麼?

    對不起noob問題!任何幫助表示讚賞。

    +0

    我正在深入這篇文章,到目前爲止,它看起來可能會得到我所需要的:http://stackoverflow.com/questions/6083372/mac-os-x-10-6-apis -report-incorrect-exif-data-for-aperture我會在驗證時報告。 –

    回答

    7

    你可以使用蘋果自己的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

    鍵=光圈值;值= 4。643856

    key = Color Space;值= 65535

    key = Custom Rendered;值= 0

    key =日期時間數字化;值= 2013:06:13 08:35:07

    key = Date Time Original;值= 2013:06:13 08:35:07

    key = Exif Version;值=( 2, 2,)

    鍵=曝光補償值;值= 0

    key =曝光模式;值= 1

    key =曝光程序;值= 1

    key =曝光時間;值= 0.0125

    key = FNumber;值= 5

    key = Flash;值= 9

    key =焦距;值= 17

    key =焦平面分辨單元;值= 2

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

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

    key = ISO Speed Ratings;值=()

    key =最大孔徑值;值= 4

    key =測光模式;值= 5

    key = Pixel X Dimension;值= 5181

    key = Pixel Y Dimension;值= 3454

    key = Scene Capture Type;值= 0

    key =快門速度值;值= 6.321928

    key = Subject Distance;值= 1.22

    key =亞秒時間數字化;值= 25

    key =亞秒時間原始值;值= 25

    key =白平衡;值= 0