-(UIImage *)blurImage:(UIImage *)image withStrength:(float)strength{ @autoreleasepool { CIContext *context = [CIContext contextWithOptions:nil]; CIImage *inputimage = [[CIImage alloc] initWithCGImage:image.CGImage]; CIFilter *filter = [CIFilter filterWithname:@"CIGaussianBlur"]; [filter setValue:inputimage forKey:@"inputimage"]; [filter setValue:[NSNumber numberWithfloat:strength] forKey:@"inputRadius"]; CIImage *result = [filter valueForKey:kCIoUtputimageKey]; float scale = [[UIScreen mainScreen] scale]; CIImage *cropped=[result imageByCropPingToRect:CGRectMake(0,image.size.wIDth*scale,image.size.height*scale)]; CGRect extent = [cropped extent]; CGImageRef cgImage = [context createCGImage:cropped fromrect:extent]; UIImage *returnImage = [UIImage imageWithCGImage:cgImage].copy; CGImageRelease(cgImage); return returnImage; }}解决方法 我在分析代码时看到了同样的泄漏.试试这个似乎可以避免泄漏并给你相同的结果:
- (UIImage*)blurImage:(UIImage*)image withStrength:(float)strength{ @autoreleasepool { CIImage* inputimage = [[CIImage alloc] initWithCGImage:image.CGImage]; CIFilter* filter = [CIFilter filterWithname:@"CIGaussianBlur"]; [filter setValue:inputimage forKey:@"inputimage"]; [filter setValue:[NSNumber numberWithfloat:strength] forKey:@"inputRadius"]; CIImage* result = [filter valueForKey:kCIoUtputimageKey]; float scale = [[UIScreen mainScreen] scale]; CIImage* cropped = [result imageByCropPingToRect:CGRectMake(0,image.size.wIDth * scale,image.size.height * scale)]; return [[UIImage alloc] initWithCIImage:cropped]; }}总结
以上是内存溢出为你收集整理的ios – CIImage内存泄漏全部内容,希望文章能够帮你解决ios – CIImage内存泄漏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)