Ich versuche GPS-Metadaten zum Bild hinzuzufügen, das mit AVFoundation
in swift aufgenommen wurde. Ich habe den Code unten eingefügt, aber es funktioniert noch nicht. Wo ist mein Fehler?GPS-Metadaten-Wörterbuch zu einem Bild hinzufügen, das mit AVFoundation in swift aufgenommen wurde
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 Methode:
private func getImageProperties(data: NSData) -> NSDictionary {
let imageSourceRef = CGImageSourceCreateWithData(data, nil);
let properties = CGImageSourceCopyPropertiesAtIndex(imageSourceRef!, 0, nil)
let props = properties
return props!
}
getGPSDictionary Methode:
private func getGPSDictionary() -> NSDictionary {
let dictionary = [kCGImagePropertyGPSLatitude as String :"54",kCGImagePropertyGPSLongitude as String :"23"]
return dictionary
}
Ja, ich weiß, dass Koordinaten bisher fest einprogrammiert sind aber wichtig, denn jetzt ist es um die Arbeit , ich werde den Standort aktualisieren.