//创建毛玻璃效果层。效果图如下。//封装高斯模糊。

CIContext *context = [CIContext contextWithOptions:nil];

CIContext *context = [CIContext contextWithOptions:nil];

//封装高斯模糊

CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage
imageNamed:@””]];

CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage
imageNamed:@”1.png”]];

  • (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;

      }                        
    

//创建高斯歪曲滤镜

// create gaussian blur filter

使用

[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;

                                    }];

CIFilter *filter = [CIFilter filterWithName:@”CIGaussianBlur”];

CIFilter *filter = [CIFilter filterWithName:@”CIGaussianBlur”];

[filter setValue:inputImage forKey:kCIInputImageKey];

[filter setValue:inputImage forKey:kCIInputImageKey];

[filter setValue:[NSNumber numberWithFloat:0]
forKey:@”inputRadius”];

[filter setValue:[NSNumber numberWithFloat:10.0]
forKey:@”inputRadius”];

//生成模糊图片

// blur image

CIImage *result = [filter valueForKey:kCIOutputImageKey];

CIImage *result = [filter valueForKey:kCIOutputImageKey];

CGImageRef cgImage = [context createCGImage:result fromRect:[result
extent]];

CGImageRef cgImage = [context createCGImage:result fromRect:[result
extent]];

UIImage *image = [UIImage imageWithCGImage:cgImage];

UIImage *image = [UIImage imageWithCGImage:cgImage];

CGImageRelease(cgImage);

CGImageRelease(cgImage);

_backImageView.image = image;

self.mainImageView.image = image;

//设置图片填充

成效图如下:

_backImageView.contentMode = UIViewContentModeScaleAspectFill;

710官方网站 1

_backImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;

//创建毛玻璃效果层

UIBlurEffect *iii = [UIBlurEffect
effectWithStyle:UIBlurEffectStyleDark];

UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc]
initWithEffect:iii];

visualEffectView.frame = _backImageView.frame;

//添加毛玻璃效果层

[_backImageView addSubview:visualEffectView];

相关文章