Image-picker display multiple images like collage without memory issue

耗尽温柔 提交于 2019-12-08 12:13:48

问题


I am using this ImagePicker to select multiple images from library or camera. Once user is done selecting images, I am storing those images in to an array. I want display images to the Frame according to number of images selected. for example, if more than 5 images selected the result will be something like this from the selected Images.

Imagepicker is new for me. I don't know how to achieve this. I've read many posts but not getting clear idea how to implement in my case.

I am testing it on Demo project given,

func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {

    imagePicker.dismiss(animated: true, completion: nil)
    imageArray = images
    createCollage()
}

func createCollage() {

}

If I use UIimageView to display/load images it shows massive memory usage.

Can please anyone help me here with any of these issue? Any help will be much appreciated!!


回答1:


look at the doc and code of ImagePicker, they are recommend to use

public var imageAssets: [UIImage] {
    return AssetManager.resolveAssets(imagePicker.stack.assets)
}

by looking for AssetManager.resolveAssets implementation we will se some config size

open static func resolveAsset(_ asset: PHAsset, size: CGSize = CGSize(width: 720, height: 1280), completion: @escaping (_ image: UIImage?) -> Void) {

set size depends from your imageView size

--- UPD

or use the property

open var preferredImageSize: CGSize?



回答2:


Tested the same code on real device and it is working fine. In my case, testing on simulator was causing massive memory usage issue here.



来源:https://stackoverflow.com/questions/45842393/image-picker-display-multiple-images-like-collage-without-memory-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!