1

1 つの画像に 10 の効果を追加するという点で、1 つの写真アプリに取り組んでいます。これにはいくつかのライブラリを使用しています。しばらくするとアプリがクラッシュします。メモリ警告を表示しています。圧縮後の画像を使用していますが、アプリもクラッシュしています。このメモリ警告を解決する方法を教えてください。画像圧縮に次のコードを使用しています

-(UIImage *)resizeImage:(UIImage *)image {
int w = image.size.width;
int h = image.size.height; 

CGImageRef imageRef = [image CGImage];

int width, height;

int destWidth = 640;
int destHeight = 480;
if(w > h){
    width = destWidth;
    height = h*destWidth/w;
} else {
    height = destHeight;
    width = w*destHeight/h;
}

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGContextRef bitmap;
bitmap = CGBitmapContextCreate(NULL, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedFirst);

if (image.imageOrientation == UIImageOrientationLeft) {
    CGContextRotateCTM (bitmap, M_PI/2);
    CGContextTranslateCTM (bitmap, 0, -height);

} else if (image.imageOrientation == UIImageOrientationRight) {
    CGContextRotateCTM (bitmap, -M_PI/2);
    CGContextTranslateCTM (bitmap, -width, 0);

} else if (image.imageOrientation == UIImageOrientationUp) {

} else if (image.imageOrientation == UIImageOrientationDown) {
    CGContextTranslateCTM (bitmap, width,height);
    CGContextRotateCTM (bitmap, -M_PI);

}

CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];

CGContextRelease(bitmap);
CGImageRelease(ref);

return result;  
}

その GPUImage ライブラリを使用しており、画像を表示するために GPUImageView を追加しました。誰かが何か考えを持っているなら、私を助けてください。前もって感謝します。

4

1 に答える 1

1

あなたは解放する必要がありますcolorspace

CGColorSpaceRelease(colorspace);

これはリークの原因である可能性がありますが、resizeImage何度も電話をかけるとクラッシュの原因になる可能性があります

于 2012-08-25T21:41:49.477 に答える