所以我一直在使用核心图像对图像应用过滤器,一切都很好,除了当我尝试一遍又一遍地应用相同的过滤器时,应用程序就退出了,我猜它是内存泄漏。
这是代码:
-(UIImage *) applyFilter: (UIImage*) picture
{
UIImageOrientation originalOrientation = picture.imageOrientation;
CGFloat originalScale = picture.scale;
CIImage *beginImage = [CIImage imageWithCGImage:picture.CGImage];
CIContext *context = [CIContext contextWithOptions:nil];
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"
keysAndValues: kCIInputImageKey, beginImage,
@"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
CIImage *outputImage = [filter outputImage];
CGImageRef cgimg =
[context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newImg = [UIImage imageWithCGImage:cgimg scale:originalScale orientation:originalOrientation];
beginImage = nil;
context = nil;
filter = nil;
outputImage = nil;
cgimg = nil;
[beginImage release];
[context release];
[filter release];
[outputImage release];
//CGImageRelease(CGImageRef) method.
CGImageRelease(cgimg);
return newImg;
}
而过滤我只是做
UIImage *ima = [self.filter applyFilter:self.imageView.image];
imageView.image = ima ;
applyFilter 是我创建的 Filter 类的一个方法