2

I am building an app which can add/modify/edit the exif after the photo filtered. The photo miss all the exif after adding filter. I have try added the new exif to the photo by attempting using the code below, which is not work. The exif still blank in the Mac App - Photos. How to fix it? THX

//Code below

  imageData = UIImageJPEGRepresentation(outp, 1.0)
    let imageSource = CGImageSourceCreateWithData(imageData! as CFData, nil)
    let filePath = NSTemporaryDirectory().appending("example.jpg")
    let fileURL = URL.init(fileURLWithPath: filePath)

    var imageInfo = CGImageSourceCopyPropertiesAtIndex(imageSource!, 0, nil) as! Dictionary<CFString, Any>

    var exifDictionay = Dictionary<CFString, Any>()
    exifDictionay = imageInfo[kCGImagePropertyExifDictionary] as! Dictionary<CFString, Any>

    exifDictionay[kCGImagePropertyExifExposureTime] = "1/3"
    exifDictionay[kCGImagePropertyExifISOSpeed] = "200"
    exifDictionay[kCGImagePropertyExifFNumber] = "2.4"
    exifDictionay[kCGImagePropertyExifApertureValue] = "3.5"
    exifDictionay[kCGImagePropertyExifFlash] = "On"
    imageInfo[kCGImagePropertyExifDictionary] = exifDictionay

    let UTI = CGImageSourceGetType(imageSource!)
    let newImageData = NSMutableData()

    CGImageDestinationAddImageFromSource(destination!, imageSource!, 0, imageInfo as CFDictionary)

    CGImageDestinationFinalize(destination!)

    PHPhotoLibrary.shared().performChanges({
        let creationRequest = PHAssetCreationRequest.forAsset()
        creationRequest.addResource(with: PHAssetResourceType.photo, data: newImageData as Data, options: nil)
    }, completionHandler: nil)
andyagul
  • 21
  • 2

0 Answers0