我正在使用Bsimagepicker
从图库中选择多个图像。 Bsimagepicker
适用于小尺寸图像,当尝试加载大尺寸高质量图像会导致
“由于内存问题而终止”
这是我的代码:
var SelectedAssets = [PHAsset]()
var PhotoArray = [UIImage]()
@objc func opengallery(_ sender: AnyObject!){
let vc = BSImagePickerViewController()
self.bs_presentImagePickerController(vc, animated: true, select: { (asset: PHAsset) -> Void in}, deselect: { (asset: PHAsset) -> Void in }, cancel: { (assets: [PHAsset]) -> Void in
let a = 1
print("hello \(a)") }, finish: { (assets: [PHAsset]) -> Void in
self.imgc = assets.count
for i in 0..<assets.count
{
self.SelectedAssets.append(assets[i])
}
self.convertAssetToImages()
}, completion: guest)
}
func convertAssetToImages() -> Void{
if SelectedAssets.count != 0{
flaggalleryin = 2
for i in 0..<SelectedAssets.count{
let manager = PHImageManager.default()
let option = PHImageRequestOptions()
var thumbflag = 0
var thumbnail = UIImage()
option.isSynchronous = true
var wid :Int!
var hei :Int!
if(SelectedAssets[i].pixelWidth > 750){
wid = 700
}else{
wid = SelectedAssets[i].pixelWidth
}
if(SelectedAssets[i].pixelHeight > 750){
hei = 700
}else{
hei = SelectedAssets[i].pixelHeight
}
manager.requestImage(for: SelectedAssets[i], targetSize: CGSize(width: wid, height: hei), contentMode: .aspectFill, options: option, resultHandler: {(result, info)->Void in
if(result != nil) {
thumbnail = result!
thumbflag = 1
}else{
thumbflag = 0
}
})
let data = UIImageJPEGRepresentation(thumbnail, 1.0)
let newImage = UIImage(data: data!)
self.PhotoArray.append(newImage! as UIImage)
}
}
请帮助我解决由于内存问题导致的终止
谢谢