使用GPUImage捕获过滤的图像并使用元数据保存到照片库

时间:2017-01-06 16:55:13

标签: ios swift gpuimage phphotolibrary gpuimagestillcamera

我正在为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)
      }
    }
  }

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

0 个答案:

没有答案