高斯模糊

左侧按钮多出20像素解决方案: if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0?20:0) {
UIBarButtonItem *negativeSpace=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpace.width=-19;
self.navigationItem.leftBarButtonItems=@[negativeSpace,[[UIBarButtonItem alloc]initWithCustomView:self.leftButton]];
}else{
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:self.leftButton];
}

pragma mark---高斯模糊

  • (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur{
    CIImage *inputImage=[CIImage imageWithCGImage:image.CGImage];
    CIFilter *filter=[CIFilter filterWithName:@"CIGaussianBlur" keysAndValues:kCIInputImageKey,inputImage,@"inputRadius", @(blur),nil];
    CIImage *outPutImage=filter.outputImage;
    CIContext *context=[CIContext contextWithOptions:nil];
    CGImageRef outImage=[context createCGImage:outPutImage fromRect:[inputImage extent]];
    return [UIImage imageWithCGImage:outImage];

}

使用方法: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:_AlbumListModel.album.coverLarge]];
dispatch_async(dispatch_get_main_queue(), ^{
[_imageView setImage:[self blurryImage:[UIImage sd_imageWithData:data] withBlurLevel:9] ];

    });
});

你可能感兴趣的:(高斯模糊)