所以,我一直在使用的核心图像对图像应用滤镜,一切都只是很好,当我尝试一遍又一遍地将相同的过滤器的应用程序只是退出,我想它的内存泄漏。
下面的代码:
-(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是我创建的过滤器类的方法