快速保存编辑后的图像metaData [英] Save edited image metaData in swift
问题描述
我正在尝试更改图像元数据并保存:
I am trying change image metaData and save it:
if let assetId = imageResult.assetIdentifier {
let assetResults = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil)
PHImageManager.default().requestImageDataAndOrientation(for: assetResults.firstObject!, options: nil,
resultHandler: { (imagedata, dataUTI, orientation, info) in
if let imageSource = CGImageSourceCreateWithData(imagedata! as CFData, nil) {
let uti: CFString = CGImageSourceGetType(imageSource)!
let dataWithEXIF: NSMutableData = NSMutableData(data: imagedata!)
let destination: CGImageDestination = CGImageDestinationCreateWithData((dataWithEXIF as CFMutableData), uti, 1, nil)!
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary
let mutable: NSMutableDictionary = imageProperties.mutableCopy() as! NSMutableDictionary
let EXIFDictionary: NSMutableDictionary = (mutable[kCGImagePropertyExifDictionary as String] as? NSMutableDictionary)!
EXIFDictionary[kCGImagePropertyExifUserComment as String] = "type:video"
mutable[kCGImagePropertyExifDictionary as String] = EXIFDictionary
CGImageDestinationAddImageFromSource(destination, imageSource, 0, (mutable as CFDictionary))
CGImageDestinationFinalize(destination)
}
})
我认为我的后两行应该将新的metaData保存在图像上,但是当我检查时仍然很旧.也许你知道为什么吗?以及如何将新的metaData保存在图像上?
I think my last two lines should save my new metaData on image but when I check is still old. Maybe you know why? And how can I save my new metaData on image?
推荐答案
您的代码中没有保存"部分.任何东西或检查"任何事物.您的代码唯一要做的就是创建一个Data对象:
There is no part of your code where you "save" anything or "check" anything. The only thing your code does is create a Data object:
let destination: CGImageDestination = CGImageDestinationCreateWithData(
(dataWithEXIF as CFMutableData), uti, 1, nil)!
然后您可以修改该Data对象,但这是不可能的.说完 finalize
后,代码结束,您将Data对象丢掉了.没有保存任何内容,也没有进行任何检查.因此,也许您正在修改该Data对象的exif,但是无法分辨.
You then may modify that Data object, but it's impossible to say; after you say finalize
, the code come to an end and you throw the Data object away. Nothing is saved and nothing checked. So maybe you are modifying the exif of that Data object, but there is no way to tell.
这篇关于快速保存编辑后的图像metaData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!