线上一张对比图:
很明显,上面的图片是是模糊的效果,而我们在实际开发中也经常使用到这样的图片作为背景,这种效果有很多方法可以做到。来说一个简单的方法,代码来咯:
//加载图片 创建imageView UIImage *image = [UIImage imageNamed:@"psb.png"]; UIImageView * imageview = [[UIImageView alloc] init]; imageview.contentMode = UIViewContentModeScaleAspectFit; imageview.frame = CGRectMake(0, 80, 320, 320); [self.view addSubview:imageview]; //转换图片 CIContext *context = [CIContext contextWithOptions:nil]; CIImage *midImage = [CIImage imageWithData:UIImagePNGRepresentation(image)]; //图片开始处理 CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; [filter setValue:midImage forKey:kCIInputImageKey]; //value 改变模糊效果值 [filter setValue:@7.0f forKey:@"inputRadius"]; CIImage *result = [filter valueForKey:kCIOutputImageKey]; CGImageRef outimage = [context createCGImage:result fromRect:[result extent]]; //转换成UIimage UIImage *resultImage = [UIImage imageWithCGImage:outimage]; imageview.image = resultImage;
是不是很简单呢
时间: 2024-10-09 08:20:27