我写了一个小功能来缩放2倍。但是在运行它时会出现EXC_BAD_ACCESS错误。以下是代码
- (CGImageRef)CGImageScale2x:(CGImageRef)imgRef
{
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGRect imgRect = CGRectMake(0, 0, width, height);
CGAffineTransform transform = CGAffineTransformMakeScale(2.0, 2.0);
CGRect scaledRect = CGRectApplyAffineTransform(imgRect, transform);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bmContext = CGBitmapContextCreate(NULL,
scaledRect.size.width,
scaledRect.size.height,
8,
0,
colorSpace,
kCGImageAlphaPremultipliedFirst);
CGContextSetAllowsAntialiasing(bmContext, FALSE);
CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
CGColorSpaceRelease(colorSpace);
CGContextScaleCTM(bmContext, 2.0, 2.0);
CGContextDrawImage(bmContext, CGRectMake(0, 0,
scaledRect.size.width,
scaledRect.size.height),
imgRef);
CGImageRef scaledImage = CGBitmapContextCreateImage(bmContext);
CFRelease(bmContext);
[(id)scaledImage autorelease];
return scaledImage;
}
我是iOS新手。请帮忙。
由于
答案 0 :(得分:1)
CGImageRef
无法自动发布,它是Core Foundation类型。请尝试使用CGImageRelease(scaledImage)
。