iOS:毛玻璃效果

使用core image
//生成一张毛玻璃图片
- (
UIImage *)blur:(UIImage *)theImage
{
   
CIContext *context = [CIContext contextWithOptions:nil];
   
CIImage *inputImage = [CIImage imageWithCGImage:theImage.CGImage];
   
   
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [filter
setValue:inputImage forKey:kCIInputImageKey];
    [filter
setValue:[NSNumber numberWithFloat:15.0] forKey:@"inputRadius"];
   
CIImage *result = [filter valueForKey:kCIOutputImageKey];
   
   
CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];
   
   
UIImage *returnImage = [UIImage imageWithCGImage:cgImage];
   
CGImageRelease(cgImage);
   
return returnImage;
}

系统方法,iOS8以上
//方法一:系统方法,iOS8及以上可用
   
if (!UIAccessibilityIsReduceTransparencyEnabled()) {
       
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
       
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
        blurEffectView.frame = _imageView.bounds;
        [
_imageView addSubview:blurEffectView];
    }

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。