这是不太常用到的,记下拉方便自己查找。
模糊效果:
UIImageView *bgImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
bgImageView.image= [UIImageimageNamed:@"bg_image"];
[self.viewaddSubview:bgImageView];
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
UIVisualEffectView *visualView = [[UIVisualEffectView alloc]initWithEffect:effect];
visualView.frame= bgImageView.bounds;
[bgImageViewaddSubview:visualView];
高斯滤镜:
CIImage *inputImage = [CIImage imageWithCGImage:[UIImage imageNamed:@"bg_image"].CGImage];
// 2、构建一个滤镜图表
CIColor*sepiaColor = [CIColorcolorWithRed:0green:0blue:1.0];
// 2.1 先构建一个 CIColorMonochrome 滤镜,并配置输入图像与滤镜参数
CIFilter *inputFilter = [CIFilter filterWithName:@"CIColorMonochrome" withInputParameters:@{@"inputColor":sepiaColor,@"inputIntensity":@0.3}];
[inputFiltersetValue:inputImageforKey:@"inputImage"];
// 2.2 先构建一个 CIVignette 滤镜
CIFilter *vignetteFilter = [CIFilter filterWithName:@"CIVignette" withInputParameters:@{@"inputRadius" : @2.0,@"inputIntensity" :@0.5}];
[vignetteFiltersetValue:inputFilter.outputImageforKey:@"inputImage"];// 以monochromeFilter的输出来作为输入
// 3、得到一个滤镜处理后的图片,并转换至 UIImage
// 创建一个 CIContext
CIContext*ciContext = [CIContextcontextWithOptions:nil];
// 将 CIImage 过渡到 CGImageRef 类型
CGImageRefcgImage = [ciContextcreateCGImage:vignetteFilter.outputImagefromRect:inputImage.extent];
// 最后转换为 UIImage 类型
UIImage*uiImage = [UIImageimageWithCGImage:cgImage];
UIImageView*imgaeView = [[UIImageViewalloc]initWithImage:uiImage];
imgaeView.frame=self.view.frame;
[self.viewaddSubview:imgaeView];