在我的应用程序中,我有一个图像数组,其中包含所有在相机上拍摄的图像。我正在使用collectionView来显示这些图像。但是,当这个图像数组达到第20张左右时,它会崩溃。我认为这是由于内存问题引起的。如何以内存高效的方式将图像存储在图像数组中?
Michael Dauterman提供了一种使用缩略图的解决方案。我希望还有其他解决方案。也许将图片存储到NSData或CoreData中?
Camera.swift:
Michael Dauterman提供了一种使用缩略图的解决方案。我希望还有其他解决方案。也许将图片存储到NSData或CoreData中?
Camera.swift:
//What happens after the picture is chosen
func imagePickerController(picker:UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject:AnyObject]){
//cast image as a string
let mediaType = info[UIImagePickerControllerMediaType] as! NSString
self.dismissViewControllerAnimated(true, completion: nil)
//if the mediaType it actually is an image (jpeg)
if mediaType.isEqualToString(kUTTypeImage as NSString as String){
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
//Our outlet for imageview
appraisalPic.image = image
//Picture taken, to be added to imageArray
globalPic = image
//image:didFinish.. if we arent able to save, pass to contextInfo in Error Handling
if (newMedia == true){
UIImageWriteToSavedPhotosAlbum(image, self, "image:didFinishSavingWithError:contextInfo:", nil)
}
}
}
NewRecord.swift
var imageArray:[UIImage] = [UIImage]()
viewDidLoad(){
//OUR IMAGE ARRAY WHICH HOLDS OUR PHOTOS, CRASHES AROUND 20th PHOTO ADDED
imageArray.append(globalPic)
//Rest of NewRecord.swift is code which adds images from imageArray to be presented on a collection view
}