【问题标题】:Converting PHAsset to UIImage and displaying it to user将 PHAsset 转换为 UIImage 并将其显示给用户
【发布时间】:2017-03-09 11:48:49
【问题描述】:

我正在使用BSImagePicker Image Picker 控制器 (See here)

图像选择器控制器返回 PHAsset 而不是 UIImage,所以我发现了如何使用此函数将 PHAsset 转换为 UIImage:

PHAsset to UIImage

func getAssetThumbnail(asset: PHAsset) -> UIImage {
    let manager = PHImageManager.default()
    let option = PHImageRequestOptions()
    var thumbnail = UIImage()
    option.isSynchronous = true
    manager.requestImage(for: asset, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: option, resultHandler: {(result, info)->Void in
        thumbnail = result!
    })
    return thumbnail
}

问题是,我想返回PHImageManagerMaximumSize 的targetSize。虽然发生这种情况时,我得到一个errorrThis application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

当我将targetSize设置为CGSize(width: 100, height: 100)时不会出现错误

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    你需要做的就是避免你的错误是强制应用程序修改主线程上的自动布局。例如,您可以在设置图像时在主队列中使用调度程序。 例如:

    let image = self.getAssetThumbnail(asset: <YourPHAsset>)
    
            DispatchQueue.main.async {
    
                self.imageView.image = image
            }
    

    当你使用targetSize...奇怪...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-15
      • 2016-11-12
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 2015-11-30
      相关资源
      最近更新 更多