ios 使用Core Image实现高斯模糊
在iOS和OS X平台上,Core Image都提供了大量的滤镜(Filter),这也是Core Image库中比较核心的东西之一。按照官方文档记载,在OS X上有120多种Filter,而在iOS上也有90多。
//使用Core Image做模糊
-(UIImage *)changeImageVague:(NSString *)imgUrl withBlurNumber:(CGFloat)blur
{
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *image = [CIImage imageWithContentsOfURL:[NSURL URLWithString:imgUrl]];//URL图片
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:image forKey:kCIInputImageKey];
[filter setValue:@(blur) forKey: @"inputRadius"];//设置多少像素的模糊
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef outImage = [context createCGImage: result fromRect:[result extent]];
UIImage * blurImage = [UIImage imageWithCGImage:outImage];
return blurImage;
}
-(UIImage *)coreBlurImage:(UIImage *)img
withBlurNumber:(CGFloat)blur {
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *image = [[CIImage alloc] initWithCGImage:img.CGImage];//本地图片
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:image forKey:kCIInputImageKey];
[filter setValue:@(blur) forKey: @"inputRadius"];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef outImage = [context createCGImage: result fromRect:[result extent]];
UIImage * blurImage = [UIImage imageWithCGImage:outImage];
return blurImage;
}
这样写会出现一个问题,就是图片会有白边,只要将CGImageRef outImage = [context createCGImage: result fromRect:[result extent]];改为CGImageRef outImage = [context createCGImage: result fromRect:[image extent]];就可以了
ios 使用Core Image实现高斯模糊的更多相关文章
- iOS 图形处理 Core Graphics Quartz2D 教程
Core Graphics Framework是一套基于C的API框架,使用了Quartz作为绘图引擎.它提供了低级别.轻量级.高保真度的2D渲染.该框架可以用于基于路径的 绘图.变换.颜色管理.脱屏 ...
- IOS之Core Foundation框架和Cocoa Foundation框架的区别
Core Foundation框架 (CoreFoundation.framework) 是一组C语言接口,它们为iOS应用程序提供基本数据管理和服务功能.下面列举该框架支持进行管理的数据以及可提供的 ...
- (转)iOS动画Core Animation
文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animat ...
- iOS 11: CORE ML—浅析
本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/OWD5UEiVu5JpYArcd2H9ig 作者:l ...
- iOS开发 - Core Animation 核心动画
Core Animation Core Animation.中文翻译为核心动画,它是一组很强大的动画处理API,使用它能做出很炫丽的动画效果.并且往往是事半功倍. 也就是说,使用少量的代码就能够实现很 ...
- iOS - Core Animation(核心动画)
Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能.Core An ...
- iOS-Core Data 详解
使用Core Data 框架 Core Data框架本质就是一个ORM(对象关系映射(英语:Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一 ...
- iOS 使用 Core Plot 绘制统计图表入门
本文转载至 http://blog.csdn.net/zhibudefeng/article/details/7677457 iOS(iPhone/iPad) 下图形组件有两个有名的,s7gra ...
- IOS利用Core Text对文字进行排版 - 转
原贴地址:http://hi.baidu.com/jwq359699768/blog/item/5df305c893413d0a7e3e6f7b.html core text 这个包默认是没有的,要自 ...
随机推荐
- python之读取cdv
csv是Comma-Separated Values的缩写,是用文本文件形式储存的表格数据,比如如下的表格: 就可以存储为csv文件,文件内容是:No.,Name,Age,Score1,Apple,1 ...
- LeetCode-Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- Legacy Notes网络和服务端配置的笔记
在云服务器上使用LAMP全过程: 第一步:传文件 在windows上下载winscp,连接使用scp协议.注意:centos需要安装scp yum install openssh-clients 即可 ...
- CSS 选择器(转)
原文转自:http://www.cnblogs.com/xyzhanjiang/p/5447406.html CSS 选择器除了样式表匹配元素时需要用到,在使用 jQuery 等库的时候也可以利用 C ...
- break,continue的使用
break,continue 使用break命令允许跳出所有循环下面的例子中,脚本进入死循环直至用户输入数字大于5.要跳出这个循环,返回到shell提示符下,就要使用break命令. #!/bin/b ...
- Ionic开发实战
转自:http://blog.csdn.net/i348018533/article/details/47258449/ 折磨的两个月!Ionic从零单排,到项目发布!遇到了很多问题但都一一解决了,此 ...
- 计算一维组合数的java实现
背景很简单,就是从给定的m个不同的元素中选出n个,输出所有的组合情况! 例如:从1到m的自然数中,选择n(n<=m)个数,有多少种选择的组合,将其输出! 本方案的代码实现逻辑是比较成熟的方案: ...
- Javascript模式(第一章简介)------读书笔记
一:模式 模式是一个通用问题的解决方案,可以提供一个更好的实践经验.有用的抽象化表示和解决一类问题的模板. 本书主要讨论如下三种类型的模式 1 设计模式:可复用面向对象软件的基础,包括singleto ...
- [Gradle]填坑记录
1.初次打开Gradle工程特别慢,一直提示下载更新Gradle 解决办法:打开Gradle工程子目录:"\gradle\wrapper" 下的 "gradle-wrap ...
- springmvc+spring-security+mybatis +redis +solar框架抽取
参考文章:Spring MVC 3 深入总结: 第二章 Spring MVC入门 —— 跟开涛学SpringMVC 参考博客:http://www.cnblogs.com/liukemng/categ ...