How to convert PHAsset to UIImage in Objective-C

后端 未结 4 2014
野的像风
野的像风 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:07

    Swift 4.2

    extension PHAsset {
    
        var image : UIImage {
            var thumbnail = UIImage()
            let imageManager = PHCachingImageManager()
            imageManager.requestImage(for: self, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: nil, resultHandler: { image, _ in
                thumbnail = image!
            })
            return thumbnail
        }
    }                          
    
    let image = asset.image 
    

提交回复
热议问题