使用core image
//生成一张毛玻璃图片
– (UIImage *)blur:(UIImage *)theImage
{
CIContext *context = [CIContextcontextWithOptions:nil];
CIImage *inputImage = [CIImageimageWithCGImage:theImage.CGImage];
CIFilter *filter = [CIFilterfilterWithName:@”CIGaussianBlur”];
[filter setValue:inputImageforKey:kCIInputImageKey];
[filter setValue:[NSNumbernumberWithFloat:15.0]forKey:@”inputRadius”];//其中数值是模糊度(3~30,越大越模糊)
CIImage *result = [filtervalueForKey:kCIOutputImageKey];
CGImageRef cgImage = [contextcreateCGImage:resultfromRect:[inputImageextent]];
UIImage *returnImage = [UIImageimageWithCGImage:cgImage];
CGImageRelease(cgImage);
return returnImage;
– (UIImage *)blur:(UIImage *)theImage
{
CIContext *context = [CIContextcontextWithOptions:nil];
CIImage *inputImage = [CIImageimageWithCGImage:theImage.CGImage];
CIFilter *filter = [CIFilterfilterWithName:@”CIGaussianBlur”];
[filter setValue:inputImageforKey:kCIInputImageKey];
[filter setValue:[NSNumbernumberWithFloat:15.0]forKey:@”inputRadius”];//其中数值是模糊度(3~30,越大越模糊)
CIImage *result = [filtervalueForKey:kCIOutputImageKey];
CGImageRef cgImage = [contextcreateCGImage:resultfromRect:[inputImageextent]];
UIImage *returnImage = [UIImageimageWithCGImage:cgImage];
CGImageRelease(cgImage);
return returnImage;
}
系统方法,iOS8以上
//方法一:系统方法,iOS8及以上可用
if (!UIAccessibilityIsReduceTransparencyEnabled()) {
UIBlurEffect *blurEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurEffectView = [[UIVisualEffectViewalloc]initWithEffect:blurEffect];
blurEffectView.frame = _imageView.bounds;
[_imageView addSubview:blurEffectView];
if (!UIAccessibilityIsReduceTransparencyEnabled()) {
UIBlurEffect *blurEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *blurEffectView = [[UIVisualEffectViewalloc]initWithEffect:blurEffect];
blurEffectView.frame = _imageView.bounds;
[_imageView addSubview:blurEffectView];
}
上述两种方法可以配合使用,效果可以增加光亮度
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/5190.html