2012-07-12 76 views
3

我使用AVFoundation捕獲UIView中的圖像並添加註釋。現在,我需要獲取捕獲圖像的地理位置。我現在的代碼片段如下所示。元數據不具有地理位置。也許我將不得不使用CLLocation?請儘快指導我。獲取使用AVFoundation的AVCaptureStillImageOutput獲取的圖像的地理位置

[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]; 
}]; 

回答

0

從我可以告訴你,你必須包裝你自己的元數據字典,並將其添加到圖像數據。

這裏是一個類擴展(通過古斯塔沃,下面的鏈接),處理寫EXIF和地理定位數據,相片中的AVCaptureStillImageOutput的API捕獲:https://github.com/gpambrozio/GusUtils/blob/master/GusUtils/NSMutableDictionary+ImageMetadata.m

而且,這裏是古斯塔沃的文章,解釋了實現:http://blog.codecropper.com/2011/05/adding-metadata-to-ios-images-the-easy-way/

HTH