これが要点です。多くの小さな画像で構成された大きな画像を持つプログラムがあり、この画像を取得して、ユーザーが移動してスクラブできる多くの小さな画像(映画のフレームなど)に分割します。
私は現在この方法を使用しています
- (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" を保持する可能性があるため、大量のメモリが消費される