美文网首页
Asset对象转为UIImage

Asset对象转为UIImage

作者: 如水的云如云的水 | 来源:发表于2018-04-12 10:00 被阅读0次

    //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)

            }

        }

    相关文章

      网友评论

          本文标题:Asset对象转为UIImage

          本文链接:https://www.haomeiwen.com/subject/hufxkftx.html