iOS开发之
来源:互联网 发布:设计本软件下载 编辑:程序博客网 时间:2024/06/06 17:00
这篇文章主要演示了三种模糊效果,如下:
一、简单的毛玻璃效果:
- 原图
原图
毛玻璃效果
毛玻璃效果
代码如下:
#import "ViewController.h"#import <CoreImage/CoreImage.h>@interface ViewController ()@property (nonatomic, strong) UIImageView *imageView;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.imageView = [[UIImageView alloc]initWithFrame:self.view.frame]; self.imageView.image = [UIImage imageNamed:@"1.jpg"]; self.imageView.contentMode = UIViewContentModeScaleAspectFill; [self.view addSubview:self.imageView]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0, self.view.frame.size.height - 80, self.view.frame.size.width, 40); [button setTitle:@"蒙奇·D·路飞" forState:UIControlStateNormal]; button.backgroundColor = [UIColor brownColor]; [button addTarget:self action:@selector("点击调用的方法") forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];}
button 被点击时调用以下代码:
self.imageView = [[UIImageView alloc] initWithFrame:self.view.frame]; self.imageView.image = [UIImage imageNamed:@"1.jpg"]; UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blur]; visualEffectView.frame = self.view.frame; [self.imageView addSubview:visualEffectView]; UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blur]; UIVisualEffectView *ano = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect]; ano.frame = self.view.frame; UILabel *label = [[UILabel alloc] init]; label.font = [UIFont systemFontOfSize:40]; label.frame = CGRectMake(0, self.view.frame.size.height - 120, self.view.frame.size.width, 80); label.textAlignment = NSTextAlignmentCenter; label.text = @"蒙奇·D·路飞"; [visualEffectView.contentView addSubview:ano]; [ano.contentView addSubview:label]; [self.view addSubview:self.imageView];
二、高斯模糊运动模糊等,先看效果图:
- 原图
原图
运动模糊效果图
运动模糊
代码如下
viewDidLoad 中的代码和“简单的毛玻璃效果”中的 viewDidLoad 是一样的,这里只简单贴出 button 被点击调用的代码
CIImage *inputImage = [CIImage imageWithCGImage:self.imageView.image.CGImage]; // CIGaussianBlur 高斯模糊 // CIBoxBlur 均值模糊 // CIDiscBlur 环形卷积模糊 // CIMotionBlur 运动模糊 CIFilter *filter = [CIFilter filterWithName:@"CIMotionBlur"]; [filter setValue:inputImage forKey:kCIInputImageKey]; [filter setValue:@5 forKey:kCIInputRadiusKey]; CIContext *context = [CIContext contextWithOptions:nil]; CIImage *outupImage = filter.outputImage; CGImageRef imageRef = [context createCGImage:outupImage fromRect:outupImage.extent]; self.imageView.image= [UIImage imageWithCGImage:imageRef];
三、滤镜效果,先看下效果图
原图
原图
“怀旧”效果图
“怀旧”效果图
- 代码如下
viewDidLoad 中的代码和“简单的毛玻璃效果”中的 viewDidLoad 是一样的,这里也只贴出 button 被点击调用的代码
CIContext *context = [CIContext contextWithOptions:nil]; CIImage *inputImage = [[CIImage alloc] initWithImage:self.imageView.image]; // 怀旧 CIPhotoEffectInstant // 单色 CIPhotoEffectMono // 黑白 CIPhotoEffectNoir // 褪色 CIPhotoEffectFade // 色调 CIPhotoEffectTonal // 冲印 CIPhotoEffectProcess // 岁月 CIPhotoEffectTransfer // 铬黄 CIPhotoEffectChrome CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectInstant"]; [filter setValue:inputImage forKey:kCIInputImageKey]; CIImage *result = [filter valueForKey:kCIOutputImageKey]; CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]]; UIImage *resultImage = [UIImage imageWithCGImage:cgImage]; self.imageView.image= [UIImage imageWithCGImage:resultImage.CGImage];
这是今晚整理的 CoreImage 相关的知识,如果哪里写的有问题,欢迎大家指正!
写在最后:FOR Freedom 看看外边的世界,以及IT这一行,少不了去Google查资料,最后,安利一个加速器代理。一枝红杏 加速器,去Google查资料是绝对首选,连接速度快,使用也方便。我买的是99¥一年的,通过这个链接(http://whosmall.com/go/yzhx)注册后输上优惠码wh80,终身85折 ,平摊下来,每月才7块钱,特实惠。
本文标签: AndroidgithubPaletteBitMap项目Google
转自 SUN'S BLOG - 专注互联网知识,分享互联网精神!
相关阅读:《关于 Android 中的 Palette 类的使用案例:色彩自适应的 Toolbar》
相关阅读:《GIT能做什么、它和SVN在深层次上究竟有什么不同》
相关阅读:《分享一些对开发者最有用的、用户友好和功能丰富的Google Chrome扩展工具》
相关阅读:《分享一些实际Android开发过程中很多相见恨晚的工具或网站》
相关阅读:《我是 G 粉,一直关注 Google,最近 Google 有一些小动作,可能很多人不太了解》
相关阅读:《机器学习引领认知领域的技术创新,那么SaaS行业会被机器学习如何改变?》
相关阅读:《VPS 教程系列:Dnsmasq + DNSCrypt + SNI Proxy 顺畅访问 Google 配置教程》
相关阅读: 对程序员有用:2017最新能上Google的hosts文件下载及总结网友遇到的各种hosts问题解决方法及配置详解
相关BLOG:SUN’S BLOG- 专注互联网知识,分享互联网精神!去看看:www.whosmall.com
原文地址:http://whosmall.com/
- IOS开发之IOS生命周期
- IOS开发之CALayer
- iOS开发之---ECSlidingViewController
- iOS开发之NSNotification
- IOS开发之路
- iOS开发之UIWebView
- ios开发之MVC
- iOS开发之label
- ios开发之NSUserDefaults
- IOS开发之UITouch
- iOS开发之UIWebView
- IOS开发之UINavigationController
- iOS开发之UIWebView
- iOS开发之归档
- iOS开发之UIViewController
- IOS开发之UITouch
- IOS开发之NSAssert
- IOS 开发之 截图
- 传输层TCP和UDP编程模型
- 泛型编程
- 关于idea中有些时候代码找不到的问题
- 简单工厂模式
- freetype中FT_Set_Transform()和FT_Load_Char()分析(待续)
- iOS开发之
- 矩阵论01—矩阵的奇异值分解
- WebService
- iOS与H5的交互【WKWebView】
- app缩略图生成策略设计
- 深入浅出RxJava演变原理
- Android 性能优化——启动时间优化指南
- Java程序员应当知道的10个面向对象设计原则
- 排序和查找算法总结