カメラで撮影した2448x3264のUIImageを回転しようとしました。私がすると、メモリはおよそ3分の1秒で約120Mbスパイクし、その後通常の状態に戻ります。問題は、メモリが少ないデバイス(iPod touchなど)では、アプリがクラッシュすることです。たとえそれがないとしても、私はそれが1つのイメージのためにそれほど多くの記憶を使うべきではないと思う。これが起こると、Iphone 5も遅れます。CGラスタデータが1つの画像に対して大きすぎます
this回答にコメントによれば、UIGraphicsGetCurrentContextを(使用した後解凍メモリのバイト単位のサイズ)の幅であるべきである*高さ* CGImageGetBitsPerComponent(image.CGImage)/ 8バイトなので、画像は8Mバイトを占めるべきではなく、120
これがなぜ起こり、どのように修正するのか、ここ
は、回転した画像を返すようにUIImageのcaterogy方法は次のとおり
:
- (UIImage *)imageRotatedByDegrees:(CGFloat)degrees {
CGFloat radian = (CGFloat) (degrees * (M_PI/ 180.0f));
CGSize rotatedSize = [self rotatedImageSize:degrees];
// Create the bitmap context
UIGraphicsBeginImageContextWithOptions(rotatedSize, NO, 0);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
CGPoint contextCenter = CGPointMake(rotatedSize.width/2.0f,
rotatedSize.height/2.0f);
CGContextTranslateCTM(bitmap, contextCenter.x, contextCenter.y);
// // Rotate the image context
CGContextRotateCTM(bitmap, radian);
// Now, draw the rotated/scaled image into the context
[self drawInRect:CGRectMake(-self.size.width/2.0f, -
self.size.height/2.0f, self.size.width, self.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
ここ回転メソッドが実行されるだけラスタデータをメモリにピークを引き起こしているものであること機器からの証明、です