简体   繁体   中英

Saving images taken from camera into NSMutableArray

First let me explain what I'm trying to do. I got a table view, that works like a stack of "albums". Each cell redirect the user to the corresponding collection view, where I load the images. For now, I let the user take a picture using the camera, and I'm using image picker controller, and then I save it in a property like this:

[[[Album sharedInstance].albumList valueForKey:@"nameOfFolder"] addObject:info[UIImagePickerControllerOriginalImage]];

The "albumList" is a NSMutableDictionary, and each value of a key (that represents a folder) is a NSMutableArray. After each new picture taken, I reload the collection view and place the picture there. But, as expected, this way I'll get a memory warning, mainly because I'm saving the original image in the array, I guess.

So my question is, what's the best way to accomplish this? I thought about saving the URL of the image in the array, and then when I need it I would retrieve this images with the URL and show them in the collection view. Another thought was to save directly to a document, without needing a array, but I think that way I would have too much processing each time I would retrieve and show the images.

So, anyone knows which approach I should take? Thanks in advance!

From my point of view, you can go with saving images directly to a document, without needing a array. You can start saving images in document in background thread.

It will take processing times but you will not get any memory issues in the application.

I recommend you clip your camera images to thumbnails, save origin images and thumbnails both in document directory. Retrieve thumbnails for table view and collection view. Retrieve origin image for image view for image details.

Big image may slow down you app performance, so avoid using big image and display it in a smal frame.

BTW, loading small images from document directory is much faster than big images.

创建一个将作为NSMutableArray副本的属性,通过这种方式,您可以更新数组,但不能直接更新,并且它不应该造成内存问题

- (NSArray *)allAlbumList { return [self.albumList copy]; //return [NSArray arrayWithArray:self.listItems];}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM