理想的には、大きな画像のUIImageオブジェクトをメモリに大量に保持しないでください。メモリに警告が表示されます。画像がローカルファイルの場合は、背景スレッドを使用して大きな画像をカルーセルに最適なサイズに拡大縮小するという1つのことを実行できます。これらのつまみの爪を保存して、元の画像にマッピングします。カルーセル用のサムネイルをロードし、元の画像ファイルを使用して詳細な画像を表示します。サムネイルは最大のパフォーマンスを得るためにpngになります。JpegデコードはiOSのネイティブではなく、pngよりも多くのcpuをデコードする必要があります。サムネイルデータをコアデータに保持するために、.pngファイルは私の経験では素晴らしい仕事をします。次のコードを使用して画像をロードできます
UIImage * image = [UIImage imageWithContentsOfFile:filePath];
画像のサイズを変更するコードは次のとおりです
- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
CGImageRef imageRef = image.CGImage;
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Set the quality level to use when rescaling
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);
CGContextConcatCTM(context, flipVertical);
// Draw into the context; this scales the image
CGContextDrawImage(context, newRect, imageRef);
// Get the resized image from the context and a UIImage
CGImageRef newImageRef = CGBitmapContextCreateImage(context);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGImageRelease(newImageRef);
UIGraphicsEndImageContext();
return newImage;
}