码迷,mamicode.com
首页 > 移动开发 > 详细

iOS:毛玻璃效果

时间:2015-02-26 14:58:15      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:ios   图片   imageview   filter   

使用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];
    }

iOS:毛玻璃效果

标签:ios   图片   imageview   filter   

原文地址:http://blog.csdn.net/u013243469/article/details/43952909

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!