// // KWMImageBlurUtil.m // iCemarose // // Created by HouWeiBin on 2017/4/28. // Copyright © 2017年 kollway. All rights reserved. // //高斯模糊工具类 #import "KWMImageBlurUtil.h" @implementation KWMImageBlurUtil +(UIImage *)getBlurImage:(UIView *)view{ //1、开启上下文 UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0); //2.获取当前上下文 CGContextRef ctx = UIGraphicsGetCurrentContext(); //3.截屏 [view.layer renderInContext:ctx]; //4、获取新图片 UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } //废弃方法,该方法会需要1-2秒,不建议使用 +(UIImage *)startBlur:(UIImage *)image withBlurNumber:(CGFloat)blur{ CIContext *context = [CIContext contextWithOptions:nil]; CIImage *inputImage= [CIImage imageWithCGImage:image.CGImage]; //设置filter CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; [filter setValue:inputImage forKey:kCIInputImageKey]; [filter setValue:@(blur) forKey: @"inputRadius"]; //模糊图片 CIImage *result=[filter valueForKey:kCIOutputImageKey]; CGImageRef outImage=[context createCGImage:result fromRect:[result extent]]; UIImage *blurImage=[UIImage imageWithCGImage:outImage]; CGImageRelease(outImage); return blurImage; } @end