【发布时间】:2014-11-07 17:20:58
【问题描述】:
以下 sn-p 代码使用 UIImage 将 CIImage 保存到磁盘。
- (void)applicationWillResignActive:(UIApplication *)application
{
NSString* filename = @"Test.png";
UIImage *image = [UIImage imageNamed:filename];
// make some image processing then store the output
CIImage *processedImage = [CIImage imageWithCGImage:image.CGImage];
#if 1// save using context
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgiimage = [context createCGImage:processedImage fromRect:processedImage.extent];
image = [UIImage imageWithCGImage:cgiimage];
CGImageRelease(cgiimage);
#else
image = [UIImage imageWithCIImage:processedImage];
#endif
// save the image
NSString *filePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[@"../Documents/" stringByAppendingString:filename]];
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
}
但是,即使调用CGImageRelease 释放CGImageRef,它也会泄露它
如果将#if 1 的行更改为#if 0,则UIImage 是直接从CIImage 创建的,并且没有内存泄漏,但是UIImage 不会保存到磁盘
【问题讨论】:
标签: ios7 memory-leaks uikit core-image