所以这里的要点是我有一个程序,它有一个由许多小图像组成的大图像,它把这个图像分成许多更小的图像(比如电影的帧),然后用户可以去浏览。
我目前使用这种方法
- (NSMutableArray *)createArrayFromImage: (NSData *)largerImageData
{
UIImage *largerImage = [UIImage imageWithData: largerImageData];
int arraySize = (int)largerImage.size.height/largerImage.size.width; //Find out how many images there are
NSMutableArray *imageArray = [[NSMutableArray alloc] init];
for (int i = 0; i < arraySize; i++) {
CGRect cropRect = CGRectMake(0, largerImage.size.width * i, largerImage.size.width, largerImage.size.width);
CGImageRef imageRef = CGImageCreateWithImageInRect([largerImage CGImage], cropRect);
UIImage *image = [UIImage imageWithCGImage: imageRef];
CGImageRelease(imageRef);
[imageArray addObject: UIImageJPEGRepresentation(image, 1.0)];
NSLog(@"Added image %d", i);
}
NSLog(@"Final size %d", (int)[imageArray count]);
return imageArray;
}
但是,由于被调用,这非常慢,UIImageJPEGRepresentation
并且如果我UIImage
直接将. 它调用[UIImageView setImage:];
如果有帮助,对此的任何帮助将不胜感激。
ED|T:CGImageCreateWithImageInRect 可能会保留“largerImage”,这会导致它占用大量内存