我正试图从使用 AVFoundation 拍摄的照片中删除 EXIF 数据,如何快速完成此操作 (2) preferred,Objective-C 也可以,我知道如何将代码转换为 swift。
为什么? 我做了我的研究,我看到了很多著名的Social Media (Reddit 来源等)确实出于身份目的和其他目的删除了 EXIF 数据。
如果您认为这是重复的帖子,请阅读我的要求并提供链接。谢谢。
最佳答案
我的回答很大程度上基于 this previous question .我调整了代码以在 Swift 2.0 上运行。
class ImageHelper {
static func removeExifData(data: NSData) -> NSData? {
guard let source = CGImageSourceCreateWithData(data, nil) else {
return nil
}
guard let type = CGImageSourceGetType(source) else {
return nil
}
let count = CGImageSourceGetCount(source)
let mutableData = NSMutableData(data: data)
guard let destination = CGImageDestinationCreateWithData(mutableData, type, count, nil) else {
return nil
}
// Check the keys for what you need to remove
// As per documentation, if you need a key removed, assign it kCFNull
let removeExifProperties: CFDictionary = [String(kCGImagePropertyExifDictionary) : kCFNull, String(kCGImagePropertyOrientation): kCFNull]
for i in 0..<count {
CGImageDestinationAddImageFromSource(destination, source, i, removeExifProperties)
}
guard CGImageDestinationFinalize(destination) else {
return nil
}
return mutableData;
}
}
然后你可以简单地做这样的事情:
let imageData = ImageHelper.removeExifData(UIImagePNGRepresentation(image))
在我的示例中,我删除了旋转和 EXIF 数据。如果您需要删除任何其他内容,您可以轻松搜索 key 。只需对生成的数据进行额外检查,因为它是可选的。
关于ios - Swift:如何从使用 AVFoundation 拍摄的照片中删除 EXIF 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32788736/