谈谈 iOS 中对图像的模糊处理
2019-08-08 本文已影响7人
腾飞tengfei
在 iOS 实际开发中,我们经常会遇到对图像添加蒙版或模糊处理,为了提高开发效率和方便大家使用,我自己写一个 DYFBlurEffect
类,先来看看效果:
效果图
BlurEffect PreviewDYFBlurEffect
用一行代码就完成对图像的模糊处理,并支持系统UIVisualEffectView,使用起来很方便,接下来一起阅读它的使用说明:
使用说明
- Instantiation
// Lazy load
- (DYFBlurEffect *)blurEffect {
if (!_blurEffect) {
_blurEffect = [[DYFBlurEffect alloc] init];
}
return _blurEffect;
}
- CoreGraphics and vImage
// Uses a `DYFBlurEffectStyle` style.
self.imgView.image = [self.blurEffect blurryImage:image style:DYFBlurEffectLight];
// Tints with a color.
self.imgView.image = [self.blurEffect blurryImage:image tintColor:[UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1]];
/**
Blur out an image with an original image, a blur radius, tint with a color, a saturation delta factor and a mask image.
*/
- (UIImage *)blurryImage:(UIImage *)image blurRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage;
- UIVisualEffectView(Available iOS 8.0 or later)
UIVisualEffectView *blurView = [self.blurEffect blurViewWithStyle:UIBlurEffectStyleLight];
blurView.frame = self.imgView.bounds;
//blurView.tag = 10;
//blurView.userInteractionEnabled = YES;
[self.view addSubview:blurView];
- CoreImage
self.imgView.image = [self.blurEffect coreImage:image blurRadius:10];
技术交流群(群号:155353383)
欢迎加入技术交流群,一起探讨技术问题。
群号:155353383