快速处理多个图像

时间:2016-07-08 20:29:19

标签: ios swift image phasset photosframework

我正在尝试开发一个iOS应用程序,用户可以从Camera Roll,Facebook,Instagram等中选择他们的图像并稍后进行编辑(裁剪,过滤,旋转)。

现在,我在使用Photos Framework加载多个图像时遇到问题,以获取PHAssets并将它们转换为全质量图像并在下一个视图中显示它们。 在SelectedImagesView中加载完整质量的图像时,我得到了内存警告,应用程序只是因为我将图像存储在内存中而被打击。

如何存储所选图像列表(原始图像和已编辑图像)并根据图像“SelectedImagesView”将其显示给用户?

1) PickImagesView

2) SelectedImagesView

到目前为止,这是我使用Photo Framework获取图像的方式:

  1. 从CollectionView
  2. 中的所选相册加载PHAssets
  3. 当用户选择图像时,将PHAsset标识符存储在NSUserDefault
  4. 当用户完成选择图像时,加载所有选定的标识符并将其发送到下一个视图
  5. 使用以下代码从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()
    }
    
  6. 但内存成本太高。 提前谢谢。

0 个答案:

没有答案