CoreImage 中的模糊滤镜

1.CoreImage 中的模糊滤镜

1.1CoreImage是苹果用来简化图片处理的框架

1.2CIImage、CIFilter与CIContext三者联系

1.3CIGaussianBlur中可能设置的参数

2.UIImage+imageEffects的category模糊效果

3.iOS8中的UIVisualEffectView模糊效果的用法

一、.CoreImage 中的模糊滤镜

- (void)coreImageBlur

{

//原始图片

UIImage *image          = [UIImage imageNamed:@"CoreImage"];

//CoreImage部分--------------------

//CIImage

CIImage *ciImage        = [[CIImage alloc]initWithImage:image];

//CIFilter

CIFilter*blurFilter     = [CIFilter filterWithName:@"CIGaussianBlur"];

//将图片输入到滤镜中

[blurFilter setValue:ciImage forKey:kCIInputImageKey];

//设置模糊程序

[blurFilter setValue:@(1) forKey:@"inputRadius"];

//用业查询滤镜可以设置的参数以及一引起相关的信息

NSLog(@"%@",[blurFilter attributes]);

//将处理好的图片输出

CIImage *outCiImage     = [blurFilter valueForKey:kCIOutputImageKey];

//CIContext

CIContext *context      = [CIContext contextWithOptions:nil];

//获取CGImage句柄

CGImageRef outCGImage   = [context createCGImage:outCiImage

fromRect:[outCiImage extent]];

//最终获取到图片

UIImage *blurImage      = [UIImage imageWithCGImage:outCGImage];

//释放CGImage句柄

CGImageRelease(outCGImage);

//---------------------------------

//

//初始化UIImageView

UIImageView *imageView = \

[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 590/2.0, 988/2.0)];

imageView.image         =  blurImage;

imageView.center        = self.view.center;

[self.view addSubview:imageView];

}

二、UIImage+ImageEffects的category
模糊效果

1.UIImage+ImageEffects是Accelerate框架中的内容

2.UIImage+ImageEffects的模糊效果非常美观

3.修改过的UIImage+ImageEffects可以对图片进行局模糊

#import "UIImage+ImageEffects.h"

- (void)effectiveImages

{

UIImage *sourceImage = [UIImage imageNamed:@"normal"];

CGSize  imageSize    = sourceImage.size;

UIImage *blurImage   = [sourceImage blurImageAtFrame:CGRectMake(0, 0,
imageSize.width/2, imageSize.height )];

UIImageView *imageView = [[UIImageView alloc]initWithImage:blurImage];

imageView.center        = self.view.center;

[self.view addSubview:imageView];

}

UIImage+ImageEffects 下载地址:http://download.csdn.net/detail/baitxaps/8893093

三、iOS8 中 UIVisualEffectView 模糊效果的使用

1.UIVisualEffectView的模糊效果是即时渲染的

2.要注意处理在UIVisualEffectiView之上的文本显示

3.只能在iOS8以上才能够使用UIVisualEffectiView

- (void)visualEffectImage

{

UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];

UIImageView *imageView      = [[UIImageView alloc]initWithImage:[UIImageimageNamed:@"normal"]];

scrollView.contentSize      = imageView.image.size;

scrollView.bounces           = NO;

[scrollView addSubview:imageView];

[self.view addSubview:scrollView];

/*添加模糊效果*/

//1.创建模糊View

UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight ]];

//2.设定尺寸

effectView.frame = CGRectMake(0, 100, 320, 200);

//3.添加到View当中

[self.view addSubview:effectView];

//4.添加显示文本

UILabel *label = [[UILabel alloc]initWithFrame:effectView.bounds];

label.text      = @"hello world";

label.font      = [UIFont systemFontOfSize:32];

label.textAlignment = NSTextAlignmentCenter;

// [effectView.contentView addSubview:label];

//5.

//添加模糊子View的UIVisualEffectView

//1.创建出子模糊View

UIVisualEffectView *subEffectView = [[UIVisualEffectView alloc]initWithEffect:[UIVibrancyEffect effectForBlurEffect:(UIBlurEffect *)effectView.effect]];

//2.设定尺寸

subEffectView.frame = effectView.bounds;

//3.将子模糊View添加到effective的contentView才能生效

[effectView.contentView addSubview:subEffectView];

//4.添加要显示的View来达到特殊的效果

[subEffectView.contentView addSubview:label];

}

四、设计下载图片后自动模糊的控件

1.用KVO监听下载完成后的事件

2.在子线程中进行渲染,主线程中进行图片的加载

3.新建一个下载类,GCD看前面博客文档GCD的封装

@interface BlurDownloadPicView : UIView

@property (nonatomic,strong)NSString *pictureUrlString;//图片下载地址

@property (nonatomic)       UIViewContentMode contentMode;//图片显示方式

//开始执行

- (void)startProgress;

@end

#import "UIImage+ImageEffects.h"

#import "BlurDownloadPicView.h"

#import "GCD.h"

@interface BlurDownloadPicView()

@property (nonatomic,strong)UIImageView *imageView;

@end

@implementation BlurDownloadPicView

- (instancetype)initWithFrame:(CGRect)frame{

self = [super initWithFrame:frame];

if (self) {

//初始化控件

//最好放一个方法中

self.imageView = [[UIImageView alloc]initWithFrame:self.bounds];

self.imageView.alpha = 0.f;

[self addSubview:self.imageView];

}

return self;

}

- (void)startProgress{

if (self.pictureUrlString)
{

[GCDQueue executeInGlobalQueue:^{

//创建请求

NSURLRequest *request = [NSURLRequest requestWithURL:

[NSURL URLWithString:self.pictureUrlString]];

//因为是同步请求,会阻塞主线程

NSData *data = [NSURLConnection sendSynchronousRequest:request

returningResponse:nil

error:nil];

UIImage *image = [[UIImage alloc]initWithData:data];

//对图片进行模糊,会阻塞主线程

UIImage *blurImage = [image blurImage];

[GCDQueue executeInMainQueue:^{

[UIView animateWithDuration:1.0 animations:^{

self.imageView.alpha = 1.f;

}];

self.imageView.image = blurImage;

}];

}];

}

}

@synthesize contentMode = _contentMode;

- (void)setContentMode:(UIViewContentMode)contentMode{

_contentMode = contentMode;

self.imageView.contentMode = contentMode;

}

- (UIViewContentMode)contentMode{

return _contentMode;

}

@end

4.使用

- (void)viewDidLoad {

[super viewDidLoad];

//[self coreImageBlur];

//[self visualEffectImage];

NSString *picUrlString = @"http://t1.mmonly.cc/uploads/allimg/tuku2/14400BR6-0.jpg";

BlurDownloadPicView *blurDownLoadView = [[BlurDownloadPicView alloc]initWithFrame:self.view.bounds];

blurDownLoadView.center               = self.view.center;

[self.view addSubview:blurDownLoadView];

blurDownLoadView.pictureUrlString = picUrlString;

blurDownLoadView.contentMode       = UIViewContentModeScaleAspectFill;

[blurDownLoadView startProgress];

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-03 15:35:37

CoreImage 中的模糊滤镜的相关文章

火云开发课堂 - 《Shader从入门到精通》系列 第十节:在Shader中实现模糊滤镜

<Shader从入门到精通>系列在线课程 第十节:在Shader中实现模糊滤镜 视频地址: http://edu.csdn.net/course/detail/1441/22674?auto_start=1 交流论坛:http://www.firestonegames.com/bbs/forum.php 工程下载地址:请成为正式学员获取工程 课程截图: 版权声明:本文为博主原创文章,未经博主允许不得转载.

iOS使用CoreImage处理图像40中可用的滤镜名称

NSString* localPath = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"jpg"]; NSURL* fileUrl = [NSURL fileURLWithPath:localPath]; CIImage* image = [CIImage imageWithContentsOfURL:fileUrl]; CIContext* context = [CIContext contextWit

PhotoShop算法实现进阶-模糊滤镜-运动模糊(二十四)

[email protected] http://blog.csdn.net/kezunhai 造成图像退化或者说使图像模糊的原因有很多种,如果是因为在摄像时相机和被摄景物之间有相对运动而造成的图像模糊则称为运动模糊.所得到图像中的景物往往会模糊不清,我们称之为运动模糊图像.运动模糊(Motion Blur)是一种抓取物体运动状态效果的滤镜,主要应用物体运动时曝光的摄影手法,模拟出在摄像中拍摄运动物体的间接曝光功能,从而使图像产生出一种动态效果.它通常用来制造物体掠过或移动的效果. 实现原理:运

PhotoShop算法实现进阶-模糊滤镜-高斯滤波(二十三)

PhotoShop算法实现进阶-模糊滤镜-高斯滤波(二十三) [email protected] http://blog.csdn.net/kezunhai 高斯模糊(Gaus Blur)采用二维高斯模板对图像进行模糊处理,用于图像模糊化(去除细节和噪声),它的处理效果给人一种更佳柔和的感觉. 一维高斯: 二维高斯: 理论上,高斯分布在所有定义域上都有非负值,这就需要一个无限大的卷积核.实际上,仅需要取均值周围3倍标准差内的值,以外部份直接去掉即可. 如下图为一个标准差为1.0的整数值高斯核:

最快的3x3中值模糊

10.1国庆后,知名博主:laviewpbt  http://www.cnblogs.com/Imageshop/ 发起了一个优化3x3中值模糊的小活动. 俺也参加其中,今天博主laviewpbt  共享了一份不错的CLAHE代码. free精神,真心为其点赞. 故俺也分享这份最快的3x3中值模糊的代码. /// 编写者: laviewpbt, 编写时间: 2015.10.16, 联系QQ: 33184777 /// <summary> /// 快速的实现3*3大小的中值模糊,边缘1像素未做处

mysql中的模糊查询

转载自:http://www.letuknowit.com/archives/90/ MySQL中实现模糊查询有2种方式:一是用LIKE/NOT LIKE,二是用REGEXP/NOT REGEXP(或RLIKE/NOT RLIKE,它们是同义词). 第一种是标准的SQL模式匹配.它有2种通配符:“_”和“%”.“_”匹配任意单个字符,而“%”匹配任意多个字符(包括0个).举例如下: SELECT * FROM table_name WHERE column_name LIKE ‘m%’; #查询

火云开发课堂 - 《Shader从入门到精通》系列 第八节:在Shader中实现黑白滤镜

<Shader从入门到精通>系列在线课程 第七节:在Shader中实现黑白滤镜 视频地址: http://edu.csdn.net/course/detail/1441/22672?auto_start=1 交流论坛:http://www.firestonegames.com/bbs/forum.php 工程下载地址:请成为正式学员获取工程 课程截图: 版权声明:本文为博主原创文章,未经博主允许不得转载.

OpenCV中值模糊方法

效果图 源码 KqwOpenCVBlurDemo 步骤 将获取到的Bitmap图片转成Mat对象 // Bitmap转为Mat Mat src = new Mat(bitmap.getHeight(), bitmap.getWidth(), CvType.CV_8UC4); Utils.bitmapToMat(bitmap, src); 调用OpenCV的中值模糊方法 // 中值模糊方法 Imgproc.medianBlur(src, src, 33); 将处理完的Mat数据转成Bitmap对象

关于ie6中使用css滤镜[_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=&#39;images/*.png&#39;,sizingMethod=&#39;scale&#39;)]后链接无法点击的问题

RT,我做的一个效果是试用png图做背景,通过_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/*.png',sizingMethod='scale');来实现,但是使用这个滤镜后,ie6下面的链接.按钮等都失效,无法点击网上搜索很多都是通过给链接加上position:relative;解决 不知道是我ie6绿色版本问题还是其他原因,我代码中加上这句无效…… 另:png透明的层我设置了绝对定位,貌似这个导