gpt4 book ai didi

ios - 将 [PHAsset] 数组转换为 [UIImage]

转载 作者:可可西里 更新时间:2023-11-01 01:09:30 24 4
gpt4 key购买 nike

有没有办法将 Phasset 数组转换为 UIImage?

var images = [PHAsset]()

func getImages() {
let assets = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: nil)
assets.enumerateObjects({ (object, count, stop) in
// self.cameraAssets.add(object)
self.images.append(object)
})

//In order to get latest image first, we just reverse the array
self.images.reverse()

最佳答案

Swift 4 中将 PHASSET 数组转换为 UIIMAGE

 //MARK: Convert array of PHAsset to UIImages
func getAssetThumbnail(assets: [PHAsset]) -> [UIImage] {
var arrayOfImages = [UIImage]()
for asset in assets {
let manager = PHImageManager.default()
let option = PHImageRequestOptions()
var image = UIImage()
option.isSynchronous = true
manager.requestImage(for: asset, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: option, resultHandler: {(result, info)->Void in
image = result!
arrayOfImages.append(image)
})
}

return arrayOfImages
}

关于ios - 将 [PHAsset] 数组转换为 [UIImage],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48505089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com