Я пытаюсь добавить метаданные GPS к изображению, снятому с AVFoundation
в быстром. У меня есть код, вставленный ниже, но он пока не работает. Где моя ошибка? Методдобавить словарь метаданных GPS в изображение, сделанное с AVFoundation in swift
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
let imgDataProvider = CGDataProviderCreateWithCFData(imageData);
let imageRef = CGImageCreateWithJPEGDataProvider(imgDataProvider, nil, true, .RenderingIntentDefault)
let properties = self.getImageProperties(imageData)
let mutableDictionary: NSMutableDictionary = NSMutableDictionary(dictionary: properties)
mutableDictionary.setValue(self.getGPSDictionary(), forKey: kCGImagePropertyGPSDictionary as String)
let newImageData = CFDataCreateMutable(nil, 0)
let type = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, "image/jpg" as CFString, kUTTypeImage)
let destination = CGImageDestinationCreateWithData(newImageData, (type?.takeRetainedValue())!, 1, nil)
CGImageDestinationAddImage(destination!, imageRef!, mutableDictionary)
CGImageDestinationFinalize(destination!)
let newImage = newImageData
getImageProperties:
private func getImageProperties(data: NSData) -> NSDictionary {
let imageSourceRef = CGImageSourceCreateWithData(data, nil);
let properties = CGImageSourceCopyPropertiesAtIndex(imageSourceRef!, 0, nil)
let props = properties
return props!
}
getGPSDictionary метод:
private func getGPSDictionary() -> NSDictionary {
let dictionary = [kCGImagePropertyGPSLatitude as String :"54",kCGImagePropertyGPSLongitude as String :"23"]
return dictionary
}
Да, я знаю, что координаты зашиты до сих пор, но важно сейчас, чтобы сделать его работу , я обновлю местоположение.