iOS 高斯模糊

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 高斯模糊)