How to convert PHAsset to UIImage in Objective-C

后端 未结 4 2082
野的像风
野的像风 2021-01-31 21:37

I have an array filled with PHAsset objects (https://developer.apple.com/library/prerelease/ios/documentation/Photos/Reference/PHAsset_Class/index.html), and I want

4条回答
  •  渐次进展
    2021-01-31 22:03

    Swift 3.0 Answer

    let photoAsset = asset
            let manager = PHImageManager.default()
            var options: PHImageRequestOptions?
            options = PHImageRequestOptions()
            options?.resizeMode = .exact
            options?.isSynchronous = true
            manager.requestImage(
                for: photoAsset,
                targetSize: PHImageManagerMaximumSize,
                contentMode: .aspectFill,
                options: options
            ) { [weak self] result, _ in
                completion(result)
            }
    

    options?.isSynchronous = true is very important

    BOOL synchronous; // return only a single result, blocking until available (or failure). Defaults to NO
    

提交回复
热议问题