2013-12-18 119 views
0

我想從使用AVFoundation捕獲的圖像獲取曝光時間。當我跟着2010年的約檢索有用的圖像元數據WWDC指令從CMSampleBuffer這樣的:iOS:從CMSampleBuffer獲取曝光時間(EXIF)

-(void)captureStillImageWithCompletion:(completion_exp)completionHandler 
{ 
AVCaptureConnection *connection = [stillImage connectionWithMediaType:AVMediaTypeVideo]; 

typedef void(^MyBufBlock)(CMSampleBufferRef, NSError*); 

MyBufBlock h = ^(CMSampleBufferRef buf, NSError *err){ 
    CFDictionaryRef exifAttachments = CMGetAttachment(buf, kCGImagePropertyExifDictionary, NULL); 
    if(exifAttachments){ 
     NSLog(@"%@",exifAttachments); 
    } 

    if(completionHandler){ 
     completionHandler(); 
    } 
}; 

[stillImage captureStillImageAsynchronouslyFromConnection:connection completionHandler:h]; 
} 

我有一個錯誤的CFDictionaryRef行:

Cannot initialize a variable of type'CFDictionaryRef (aka 'const __CFDictionary*') with an rvalue of type CFTypeRef.. 

於是我接着鑄造的互聯網解決方案它是這樣的:

CFDictionaryRef exifAttachments = (CFDictionaryRef)CMGetAttachment(buf, kCGImagePropertyExifDictionary, NULL); 

而現在它給了我另一個錯誤:未定義的符號體系結構armv7s

(Apple Mach-o Linker Error: "_kCGImagePropertyExifDictionary", referenced from:) 
(Apple Mach-o Linker Error: "_CMGetAttachment", referenced from:) 

我不明白我的程序出了什麼問題。任何人有任何想法?

回答

1

編輯:你必須包括ImageIO庫和標題,使這個關鍵的工作。如果你不想這樣做,你可以使用這個:

有一些關於我認爲的關鍵。這對我有效:

CFDictionaryRef exifAttachments = CMGetAttachment(buf, (CFStringRef)@"{Exif}" , NULL); 
+0

添加ImageIO框架爲我工作,謝謝! – jungledev

1

也掙扎着,我發現你可以簡單地將Exif附件作爲NSDictionary轉換。我希望這會幫助任何人。

let metadata = CMGetAttachment(image, "{Exif}", nil) as! NSDictionary 
let buf = metadata.valueForKey("ExposureTime") as! NSNumber 
let xposure:Double = buf.doubleValue 
相關問題