1

我正在尝试从使用AVFoundation. 当我遵循 2010 年的 WWDC 指令时,关于从中检索有用的图像元数据CMSampleBuffer

-(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);

现在它给了我另一个错误:Undefined symbols for architecture armv7s

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

我不明白我的程序出了什么问题。有人有什么想法吗?

4

3 回答 3

3

Philli 对Swift4回答的修改版:

var exifEd: Double?
if let metadata = CMGetAttachment(sampleBuffer, key: "{Exif}" as CFString, attachmentModeOut: nil) as? NSDictionary {
    if let exposureDurationNumber = metadata.value(forKey: "ExposureTime") as? NSNumber {
        exifEd = exposureDurationNumber.doubleValue
    }
}
于 2019-04-19T14:18:28.800 回答
2

编辑:您必须包含 ImageIO 库和标头才能使此密钥起作用。如果你不想这样做,你可以使用这个:

我认为这把钥匙有些东西。这对我有用:

CFDictionaryRef exifAttachments = CMGetAttachment(buf, (CFStringRef)@"{Exif}", NULL);
于 2013-12-30T04:23:20.630 回答
2

也在为此苦苦挣扎,我发现您可以简单地将 Exif 附件转换为 NSDictionary。我希望这会帮助任何人。

let metadata = CMGetAttachment(image, "{Exif}", nil ) as! NSDictionary
let buf = metadata.valueForKey("ExposureTime") as! NSNumber
let xposure:Double = buf.doubleValue
于 2016-02-22T19:06:47.217 回答