I'm editing an NSImage which is read from disk.The original image has exif info like the camera make, location etc. When saving the NSImage , this EXIF info is lost. I'm using the following code to write the NSImage to disk.
let cgRef = modifiedImage.cgImage(forProposedRect: nil, context: nil, hints: nil)
var newRep: NSBitmapImageRep ? = nil
if let aRef = cgRef {
newRep = NSBitmapImageRep(cgImage: aRef)
}
newRep?.size = modifiedImage.size ?? NSSize.zero
let filepath = URL(fileURLWithPath: imageURL + ".png")
let dataToSave = newRep?.representation(using: NSBitmapImageRep.FileType.png, properties: [NSBitmapImageRep.PropertyKey.compressionFactor: 1])
do {
try dataToSave?.write(to: filepath)
return true
} catch {
return false
}
How can i copy the exif info from the original image to the saved one?