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

作者: 腾飞Tenfay | 来源:发表于2019-08-08 23:12 被阅读7次

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

效果图

BlurEffect Preview

DYFBlurEffect用一行代码就完成对图像的模糊处理,并支持系统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

Sample Codes

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

相关文章

网友评论

    本文标题:谈谈 iOS 中对图像的模糊处理

    本文链接:https://www.haomeiwen.com/subject/onnjrctx.html