美文网首页
高斯模糊的使用(毛玻璃效果)

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

作者: 十年祤茉 | 来源:发表于2016-09-07 16:39 被阅读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;
    
                                        }];

    相关文章

      网友评论

          本文标题:高斯模糊的使用(毛玻璃效果)

          本文链接:https://www.haomeiwen.com/subject/arwjettx.html