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 = \

/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;

, ,
imageSize., 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., , , );

//3.加入到View其中

[self.view addSubview:effectView];

//4.加入显示文本

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

label.text      = @"hello world";

label.];

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

}




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

  1. mysql中的模糊查询

    转载自:http://www.letuknowit.com/archives/90/ MySQL中实现模糊查询有2种方式:一是用LIKE/NOT LIKE,二是用REGEXP/NOT REGEXP(或 ...

  2. Mybatis中的模糊查询

    今天下午做的一个功能,要用到模糊查询,字段是description,刚开始我的写法用的是sql中的模糊查询语句, 但是这个有问题,只有将字段的全部值传入其中,才能查询,所以不是迷糊查询. 后来经过搜索 ...

  3. 最快的3x3中值模糊

    10.1国庆后,知名博主:laviewpbt  http://www.cnblogs.com/Imageshop/ 发起了一个优化3x3中值模糊的小活动. 俺也参加其中,今天博主laviewpbt   ...

  4. mongo中的模糊查询

    以下是一个mongo查询的综合应用,即介绍一个生产中实际应用的模糊查询,当然其实也很简单,主要用到mongo中的模糊查询和$or查询,以及并的关系,下面是一个mongo中的一条记录 { "_ ...

  5. 解决 canvas 绘图在高清屏中的模糊问题

    解决 canvas 绘图在高清屏中的模糊问题 为什么模糊 CSS 像素是一个抽象单位(1 px),浏览器根据某种规则将 css 像素转化为屏幕需要的实际像素值. 在高清屏之前,屏幕上显示一个像素点需要 ...

  6. MySQL中的模糊查询和通配符转义

    MySQL中实现模糊查询有2种方式:一是用LIKE/NOT LIKE,二是用REGEXP/NOT REGEXP(或RLIKE/NOT RLIKE,它们是同义词). 第一种是标准的SQL模式匹配.它有2 ...

  7. 【Django】Django中的模糊查询以及Q对象的简单使用

    Django中的模糊查询: 需要做一个查找的功能,所以需要使用到模糊查询. 使用方法是:字段名加上双下划线跟上contains或者icontains,icontains和contains表示是否区分大 ...

  8. Flash中如何使用滤镜

    使用滤镜 应用或删除滤镜 复制和粘贴滤镜 为对象应用预设滤镜 启用或禁用应用于对象的滤镜 启用或禁用应用于对象的所有滤镜 创建预设滤镜库 对象每添加一个新的滤镜,在属性检查器中,就会将其添加到该对象所 ...

  9. Emgu-WPF学习使用-中值模糊

    原文:Emgu-WPF学习使用-中值模糊 实现效果: 实现途径: 前提:Image File-> System.Drawing.Bitmap->Image<Bgr, byte> ...

随机推荐

  1. asp.net给文件分配自己主动编号,如【20140710-1】

    在开发办公软件的时候,须要给非常多文件什么的东西分配一个编号.是依照日期来的,比方2014.07.10的第一个文件编号就为20140710-1,这一天的第二个文件编号就为20140710-2,以此类推 ...

  2. iOS开发技巧 - 使用UIDatePicker来选择日期和时间

    (Swift) import UIKit class ViewController: UIViewController { var datePicker: UIDatePicker! func dat ...

  3. POSTGRESQL 查看数据库 数据表大小

    1.查看数据库大小: select pg_database_size('log_analysis'); select pg_database_size('log_analysis'); pg_data ...

  4. JAVA设计模式——第 8 章 适配器模式【Adapter Pattern】(转)

    好,请安静,后排聊天的同学别吵醒前排睡觉的同学了,大家要相互理解嘛.今天讲适配器模式,这个模式也很简单,你笔记本上的那个拖在外面的黑盒子就是个适配器,一般你在中国能用,在日本也能用,虽然两个国家的的电 ...

  5. webbrowser载入地图网页出现脚本错误解决

    对于这个问题.我整整花了一上午的时间来解决,网上关于此问题的解决差点儿找不到,于是我就尽能够能的从网上相关问题的答案中获取些灵感.功夫不负有心人.最终通过这些灵感的积累我最终攻克了此问题. 首先让我们 ...

  6. Redis问题MISCONF Redis is configured to save RDB snapshots....

    Redis问题MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on di ...

  7. MySQL 简单存储过程实现Redis的INCR功能

    USE test; DROP PROCEDURE IF EXISTS pro_testincrement; DELIMITER && CREATE PROCEDURE pro_test ...

  8. Android学习笔记八:用Broadcast Receiver跨进程(跨app)通信

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/7515194.html 在前面介绍四大组件的时候提到了可以对外部事件进行过滤的Broadcast Receive ...

  9. PgSql备份pg_dump与还原手记pg_restore

    真没有想到,以前一直是PostgreSQL使用者,突然需要库移植又成了头一招了!原来它与mysql命令行操作区别还挺大.不用怕,但绝对要细心,因为数据库操作是网站的核心,一旦出现损坏或丢失,后果就非常 ...

  10. 【超精简JS模版库/前端模板库】原理简析 和 XSS防范

    使用jsp.php.asp或者后来的struts等等的朋友,不一定知道什么是模版,但一定很清楚这样的开发方式: <div class="m-carousel"> < ...