ios – CIImage内存泄漏

ios – CIImage内存泄漏,第1张

概述我正在使用以下方法模糊一些图像.使用仪器CI Image正在泄漏.我尝试将它们包装在@autoreleasepool中,但没有运气.有任何想法吗? -(UIImage *)blurImage:(UIImage *)image withStrength:(float)strength{ @autoreleasepool { CIContext *context = [CIC 我正在使用以下方法模糊一些图像.使用仪器CI Image正在泄漏.我尝试将它们包装在@autoreleasepool中,但没有运气.有任何想法吗?

-(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内存泄漏所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1010328.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存