1

我正在为 iOS 10 开发一个简单的应用程序。我需要实时过滤相机提要,然后捕获并保存过滤后的图像。

使用 GPUImage,我已经能够使用GPUImageStillCamera. 我也在使用PHPhotoLibraryAPI:

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)
      }
    }
  }

问题是当这张图片被保存时,元数据(例如相机和设备信息)丢失了。如何使用过滤器保存此图像,但仍保留图像元数据?

4

0 回答 0