获取使用AVFoundation的AVCaptureStillImageOutput捕获的图像的地理位置

时间:2012-07-12 11:06:23

标签: ios geolocation avfoundation

我使用AVFoundation捕获UIView中的图像并为其添加注释。现在,我需要获取捕获图像的地理位置。我目前的代码段如下所示。元数据没有地理位置。也许我将不得不使用CLLocation?请尽快指导我。

[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
 {
     CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL, imageSampleBuffer, kCMAttachmentMode_ShouldPropagate);
     NSMutableDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:(__bridge NSDictionary*)metadataDict];
     CFRelease(metadataDict);
     NSLog(@"%@",metadata);
     CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
     if (exifAttachments)
     {
         // Do something with the attachments.
     }
     else
         NSLog(@"no attachments");

     NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
     [captureSession stopRunning];
     [imageData writeToFile:path atomically:YES];
 }];

1 个答案:

答案 0 :(得分:0)

据我所知,你必须包装你自己的元数据字典并将其添加到图像数据中。

这是一个类扩展(By Gustavo,下面的链接),它处理将EXIF和地理位置数据写入使用AVCaptureStillImageOutput apis捕获的照片:https://github.com/gpambrozio/GusUtils/blob/master/GusUtils/NSMutableDictionary+ImageMetadata.m

此外,这是Gustavo的文章解释了实施:http://blog.codecropper.com/2011/05/adding-metadata-to-ios-images-the-easy-way/

HTH