我正在为iOS 10开发一个简单的应用程序。我需要实时过滤相机Feed,然后捕获并保存过滤后的图像。
使用GPUImage,我可以使用GPUImageStillCamera
设置实时反馈和图像捕获。我也在使用PHPhotoLibrary
API:
func saveToPhotoLibrary(data: Data, completion: @escaping (PHAsset?) -> ()) {
var assetIdentifier: String?
PHPhotoLibrary.requestAuthorization { (status) in
if status == .authorized {
PHPhotoLibrary.shared().performChanges({
let creationRequest = PHAssetCreationRequest.forAsset()
let placeholder = creationRequest.placeholderForCreatedAsset
creationRequest.addResource(with: .photo, data: data, options: .none)
assetIdentifier = placeholder?.localIdentifier
}, completionHandler: { (success, error) in
if let error = error {
print("There was an error saving to the photo library: \(error)")
}
var asset: PHAsset? = .none
if let assetIdentifier = assetIdentifier {
asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetIdentifier], options: .none).firstObject
}
completion(asset)
})
} else {
print("Need authorisation to write to the photo library")
completion(.none)
}
}
}
问题是当保存此图像时,缺少元数据(例如相机和设备信息)。如何使用过滤器保存此图像,但仍保留图像元数据?