我正在尝试开发一个iOS应用程序,用户可以从Camera Roll,Facebook,Instagram等中选择他们的图像并稍后进行编辑(裁剪,过滤,旋转)。
现在,我在使用Photos Framework加载多个图像时遇到问题,以获取PHAssets并将它们转换为全质量图像并在下一个视图中显示它们。 在SelectedImagesView中加载完整质量的图像时,我得到了内存警告,应用程序只是因为我将图像存储在内存中而被打击。
如何存储所选图像列表(原始图像和已编辑图像)并根据图像“SelectedImagesView”将其显示给用户?
到目前为止,这是我使用Photo Framework获取图像的方式:
使用以下代码从SelectedImagesView中的照片库加载图像:
func processImages() {
for identifier in self.selectedAssets {
let options = PHImageRequestOptions()
options.deliveryMode = .FastFormat
// request images no bigger than 1/3 the screen width
let maxDimension = UIScreen.mainScreen().bounds.width / 3 * UIScreen.mainScreen().scale
let size = CGSize(width: maxDimension, height: maxDimension)
let assets = PHAsset.fetchAssetsWithLocalIdentifiers([identifier], options: nil)
guard let asset = assets.firstObject as? PHAsset
else { fatalError("no asset") }
PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: PHImageManagerMaximumSize, contentMode: .AspectFill, options: options)
{ result, info in
// probably some of this code is unnecessary, too,
// but I'm not sure what you're doing here so leaving it alone
let photo: Photo = Photo()
photo.originalPhoto = result
self.selectedImages.append(photo)
}
}
self.tableView!.reloadData()
self.tableView!.reloadInputViews()
}
但内存成本太高。 提前谢谢。