高斯模糊的使用(毛玻璃效果)

2016-09-07  本文已影响61人  十年祤茉

//封装高斯模糊
+ (UIImage *)coreBlurImage:(UIImage *)image
withBlurNumber:(CGFloat)blur
{
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [CIImage i mageWithCGImage:image.CGImage];
//设置filter
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:inputImage forKey:kCIInputImageKey];
[filter setValue:@(blur) forKey:@"inputRadius"];
//模糊图片
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CIImage *tmpImage = [CIImage imageWithCGImage:image.CGImage];
CGImageRef outImage = [context createCGImage:result fromRect:[tmpImage extent]];
UIImage *blurImage = [UIImage imageWithCGImage:outImage];
CGImageRelease(outImage);

return blurImage;
    }                        

使用

[self.backgroundView sd_setImageWithURL:tmpUrl
                             placeholderImage:[UIImage imageNamed:@"me_bg"]
                                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                                        UIImage *tmpImage = [UIImage coreBlurImage:image withBlurNumber:30.0];
                                        self.backgroundView.image = tmpImage;

                                    }];
上一篇下一篇

猜你喜欢

热点阅读