UIImage +调整崩溃没有内存警告

时间:2012-02-01 20:33:45

标签: xcode ios4 uiimage image-resizing

Herer是我调整大小的例程...... 在CGContextDrawImage行中,应用程序在2或3次例程调用后崩溃。

没有内存警告或其他内容。 它只是崩溃

- (UIImage *)resizedImage:(CGSize)newSize
                transform:(CGAffineTransform)transform
           drawTransposed:(BOOL)transpose
     interpolationQuality:(CGInterpolationQuality)quality {
    CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
    CGRect transposedRect = CGRectMake(0, 0, newRect.size.height, newRect.size.width);


    CGImageRef imageRef = self.CGImage;

    // Build a context that's the same dimensions as the new size
    CGContextRef bitmap = CGBitmapContextCreate(NULL,
                                                newRect.size.width,
                                                newRect.size.height,
                                                CGImageGetBitsPerComponent(imageRef),
                                                0,
                                                CGImageGetColorSpace(imageRef),
                                                CGImageGetBitmapInfo(imageRef));

    // Rotate and/or flip the image if required by its orientation
    CGContextConcatCTM(bitmap, transform);

    // Set the quality level to use when rescaling
    CGContextSetInterpolationQuality(bitmap, quality);

    // Draw into the context; this scales the image


////////////AFTER THAT IT CRASHS!!!


     CGContextDrawImage(bitmap, transpose ? transposedRect : newRect, imageRef);

        // Get the resized image from the context and a UIImage
        CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap);
        UIImage *newImage = [UIImage imageWithCGImage:newImageRef];

        // Clean up
        CGContextRelease(bitmap);
        CGImageRelease(newImageRef);

        return newImage;
    }

有人提示?

问候,phil

1 个答案:

答案 0 :(得分:1)

也许您应该为ARC添加autorelease pool@autorelease{}? 我想,这会有所帮助。

相关问题