CGImageRef imgRef = [image CGImage]; 通过此种方式的得到的CGImageRef不能利用CGImageRelease释放,因为你不拥有它所以不用释放
在ios中特定形状剪裁图片的实现(注意要释放内存,不然即使用ARC也会出现内存泄露)
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)mask
{
CGImageRef imgRef = [image CGImage];
CGImageRef maskRef = [mask CGImage];
CGImageRef actualMask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, NO);
CGImageRef masked = CGImageCreateWithMask(imgRef, actualMask);
UIImage *newImage = [UIImage imageWithCGImage:masked];
CGImageRelease(actualMask);
CGImageRelease(masked);
return newImage;
}