CoreImage的模糊滤镜
//1.原始图片 UIImage * image = [UIImage imageNamed:@"1.jpg"]; /****************core image******************/ //a.图片 CIImage * ciImage = [[CIImage alloc] initWithImage:image]; //b.滤镜 CIFilter * ciFilter = [CIFilter filterWithName:@"CIGaussianBlur"]; NSLog(@"%@",[ciFilter attributes]); //设置滤镜的模糊程度,默认是10 [ciFilter setValue:@(10) forKey:@"inputRadius"]; //将图片放到滤镜中 [ciFilter setValue:ciImage forKey:kCIInputImageKey]; //输出图片 CIImage * outImage = [ciFilter valueForKey:kCIOutputImageKey]; //c.获取CGImage的句柄 CIContext * context = [CIContext contextWithOptions:nil]; CGImageRef outCGImage = [context createCGImage:outImage fromRect:[outImage extent]]; UIImage * blurImage = [UIImage imageWithCGImage:outCGImage]; CGImageRelease(outCGImage); /********************************************/ //2.初始化imageView UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 200)]; imageView.image = blurImage; [self.view addSubview:imageView];