iOS 高斯模糊

作者: any_where | 来源:发表于2016-03-11 17:02 被阅读475次

CIContext *context = [CIContext contextWithOptions:nil];

CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@""]];

//创建高斯模糊滤镜

CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];

[filter setValue:inputImage forKey:kCIInputImageKey];

[filter setValue:[NSNumber numberWithFloat:0] forKey:@"inputRadius"];

//生成模糊图片

CIImage *result = [filter valueForKey:kCIOutputImageKey];

CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]];

UIImage *image = [UIImage imageWithCGImage:cgImage];

CGImageRelease(cgImage);

_backImageView.image = image;

//设置图片填充

_backImageView.contentMode = UIViewContentModeScaleAspectFill;

_backImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

//创建毛玻璃效果层

UIBlurEffect *iii = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:iii];

visualEffectView.frame = _backImageView.frame;

//添加毛玻璃效果层

[_backImageView addSubview:visualEffectView];

相关文章

网友评论

    本文标题:iOS 高斯模糊

    本文链接:https://www.haomeiwen.com/subject/rvcxlttx.html