Exif 添加/修改/编辑照片';斯威夫特进出口银行

Exif 添加/修改/编辑照片';斯威夫特进出口银行,exif,photokit,phphotolibrary,cgimagesource,Exif,Photokit,Phphotolibrary,Cgimagesource,我正在构建一个应用程序,可以在照片过滤后添加/修改/编辑exif。添加过滤器后,照片将丢失所有exif。我尝试使用下面的代码将新的exif添加到照片中,但这不起作用。Mac应用程序-照片中的exif仍然为空。如何修复它? THX //代码如下 imageData = UIImageJPEGRepresentation(outp, 1.0) let imageSource = CGImageSourceCreateWithData(imageData! as CFData, nil)

我正在构建一个应用程序,可以在照片过滤后添加/修改/编辑exif。添加过滤器后,照片将丢失所有exif。我尝试使用下面的代码将新的exif添加到照片中,但这不起作用。Mac应用程序-照片中的exif仍然为空。如何修复它? THX

//代码如下

  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)
imageData=UIImageJPEG表示法(输出,1.0)
让imageSource=CGImageSourceCreateWithData(imageData!作为CFData,为零)
让filePath=NSTemporaryDirectory().appending(“example.jpg”)
让fileURL=URL.init(fileURLWithPath:filePath)
var imageInfo=CGImageSourceCopyPropertiesAtIndex(imageSource!,0,nil)as!字典
var exifDictionay=Dictionary()
ExifDictionary=imageInfo[kCGImagePropertyExifDictionary]as!字典
ExifDictionary[KCGimagePropertyExifExposure]=“1/3”
ExifDictionary[kCGImagePropertyExifISOSpeed]=“200”
ExifDictionary[kCGImagePropertyExifFNumber]=“2.4”
ExifDictionary[kCGImagePropertyExifApertureValue]=“3.5”
ExifDictionary[KCGimagePropertyExiflash]=“打开”
imageInfo[kCGImagePropertyExifDictionary]=ExiFDictionary
让UTI=CGImageSourceGetType(imageSource!)
让newImageData=NSMutableData()
CGImageDestinationAddImageFromSource(目的地!、imageSource!、0、imageInfo作为CFDictionary)
CGImageDestinationFinalize(目的地!)
PHPhotoLibrary.shared().performChanges({
让creationRequest=PhaseSetCreationRequest.forAsset()
creationRequest.addResource(带有:PHAssetResourceType.photo,数据:newImageData作为数据,选项:nil)
},completionHandler:nil)