//asset对象转UIimage
func getImageFromPHAsset(asset: PHAsset, result: (_ data: NSData?, _ fileName: String?) -> Void) {
var data = NSData.init()
if asset.mediaType == PHAssetMediaType.image {
let options = PHImageRequestOptions.init()
options.version = PHImageRequestOptionsVersion.current
options.deliveryMode = PHImageRequestOptionsDeliveryMode.highQualityFormat
options.isSynchronous = true
PHImageManager.default().requestImageData(for: asset, options: options, resultHandler: { (imageData, dataUTI, orientation, info) in
data = NSData.init(data: imageData!)
})
}
let filName = asset.value(forKey: "filename") as? String
if data.length > 0 {
result(data, filName)
} else {
result(nil, nil)
}
}
网友评论