这是一段突出显示部分屏幕的代码,我想知道此代码中是否有任何泄漏:
- (UIImage*)createImageSection:(UIImage*)image section:(CGRect)section
{
UIScreen *screen = [UIScreen mainScreen];
float originalWidth = image.size.width * [screen scale] ;
float originalHeight = image.size.height * [screen scale];
int w = originalWidth * section.size.width ;
int h = originalHeight * section.size.height ;
CGContextRef ctx = CGBitmapContextCreate(nil, w , h , 8, w * 8, CGImageGetColorSpace([image CGImage]), kCGImageAlphaPremultipliedLast);
CGContextClearRect(ctx, CGRectMake(0, 0, originalWidth * section.size.width * [screen scale], originalHeight * section.size.height * [screen scale])); // w + h before
CGContextTranslateCTM(ctx, (float)-originalWidth * section.origin.x , (float)-originalHeight * section.origin.y );
CGContextDrawImage(ctx, CGRectMake(0, 0, originalWidth , originalHeight ), [image CGImage]);
CGImageRef cgImage = CGBitmapContextCreateImage(ctx);
//UIImage* resultImage = [[UIImage alloc] initWithCGImage:cgImage scale: [screen scale]];
UIImage* resultImage = [[UIImage alloc] initWithCGImage:cgImage scale:[screen scale] orientation:UIImageOrientationUp] ;
CGContextRelease(ctx);
CGImageRelease(cgImage);
return resultImage ;
}
由于 DKV
答案 0 :(得分:-1)
Autorelease resultImage
UIImage* resultImage = [[UIImage alloc] initWithCGImage:cgImage scale:[screen scale] orientation:UIImageOrientationUp]
到
UIImage* resultImage = [[[UIImage alloc] initWithCGImage:cgImage scale:[screen scale] orientation:UIImageOrientationUp] autorelease];