I am trying to save SOME of the metadata from an image sample buffer along with the image.
I need to:
I made a greatly simplified version of the code above. It does make an image file, but as Carlos has noted, no custom metadata is in the file when you load it up again. According to other threads, this simply may not be possible.
func saveImage(_ image: UIImage, withMetadata metadata: NSMutableDictionary, atPath path: URL) -> Bool {
guard let jpgData = UIImageJPEGRepresentation(image, 1) else {
return false
}
// make an image source
guard let source = CGImageSourceCreateWithData(jpgData as CFData, nil), let uniformTypeIdentifier = CGImageSourceGetType(source) else {
return false
}
// make an image destination pointing to the file we want to write
guard let destination = CGImageDestinationCreateWithURL(path as CFURL, uniformTypeIdentifier, 1, nil) else {
return false
}
// add the source image to the destination, along with the metadata
CGImageDestinationAddImageFromSource(destination, source, 0, metadata)
// and write it out
return CGImageDestinationFinalize(destination)
}