IT/互联网Mac·iOS开发iOS 开发继续加油

谈谈 iOS 中对图像的模糊处理

2019-08-08  本文已影响7人  腾飞tengfei

在 iOS 实际开发中,我们经常会遇到对图像添加蒙版或模糊处理,为了提高开发效率和方便大家使用,我自己写一个 DYFBlurEffect 类,先来看看效果:

效果图

BlurEffect Preview

DYFBlurEffect用一行代码就完成对图像的模糊处理,并支持系统UIVisualEffectView,使用起来很方便,接下来一起阅读它的使用说明:

使用说明

// Lazy load
- (DYFBlurEffect *)blurEffect {
    if (!_blurEffect) {
        _blurEffect = [[DYFBlurEffect alloc] init];
    }
    return _blurEffect;
}
// 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 *blurView = [self.blurEffect blurViewWithStyle:UIBlurEffectStyleLight];
blurView.frame = self.imgView.bounds;
//blurView.tag = 10;
//blurView.userInteractionEnabled = YES;
[self.view addSubview:blurView];
 self.imgView.image = [self.blurEffect coreImage:image blurRadius:10];

技术交流群(群号:155353383)

欢迎加入技术交流群,一起探讨技术问题。

群号:155353383

Sample Codes

如果你觉得能帮助到你,请去Github项目给一颗小星星。谢谢!(If you think it can help you, please go to the github project and give it a star. Thanks!)

上一篇下一篇

猜你喜欢

热点阅读