Getting a CGImageRef from UIImage through image.CGImage can be expensive. From the documentation:
If image data has been cleared due to memory limitations, calling this method forces the data to be loaded back into memory. Reloading image data may result in poor performance.
If you are comfortable mixing C ++ and Objective-C, you can use std :: vector to store CGImageRef. Rename the source file from .m to .mm and try the following:
#include <vector>
...
CGImageRef i;
...
std::vector<CGImageRef> images;
images.push_back(i);
If you want to save the vector as a member of the Objective-C class, you must allocate it on the heap and not on the stack:
Header file:
#include <vector>
using std;
@interface YourInterface : ...
{
vector<CGImageRef> *images;
}
and in the implementation file:
images = new std::vector<CGImageRef>();
images->push_back(i);
...
delete images;
images = NULL;
source
share