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

在 iOS 开发中,我们经常会遇到给图像添加蒙版、模糊效果或者毛玻璃处理,为了提高开发效率和方便各位小伙伴使用,我专门写一个 DYFBlurEffect 类,先来看看效果。

预览

Blur Effect 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];

最后

附上 DYFBlurEffect 项目地址,觉得还行呢,麻烦顺手给个star。对开发实现图像的模糊处理功能的小伙伴,希望能够解决你的一些问题。即使不能,也希望能给你提供一些思路。

DYFBlurEffect =>【https://github.com/dgynfi/DYFBlurEffect

支持 Pods,在 Podfile 文件中添加:pod 'DYFBlurEffect'。


点赞+关注,第一时间获取技术干货和最新知识点,谢谢你的支持!

最后祝大家生活愉快~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS7后,半透明模糊效果得到了广泛的使用,所以iOS开发过程中经常需要用到半透明模糊效果,本文对比列举几种实现半...
    乒什么乓阅读 28,216评论 18 85
  • 这几天因为各种天气相互交叉变化,我很幸运的中奖了,唉,得了一个大感冒。但是呢,好像每一次生病咋的,都会心情超级不好...
    梦夏阅读 467评论 0 1
  • 当她刚到楼下,等着师傅停车好准备下车,突然路边阴影里一辆车冲着她直撞过来。幸好今天搭的顺风车师傅反应快,马上加油打...
    悦读山人阅读 221评论 1 3
  • 线上故障是指提供给客户使用的IT服务全部或部分不可用,包括服务性能的降低,如:服务延迟导致用户体验变差。在创业前期...
    moooofly_28e4阅读 626评论 0 1
  • 春天,天气渐暖,太阳露出了灿烂的笑容。霸占了一冬季的天空上的浓暗深乌的冷云终于散消开了,天空像是被打扫得干干净净全...
    贺卿茵阅读 416评论 0 3