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 = \
/2.0)];
imageView.image = blurImage;
imageView.center = self.view.center;
[self.view addSubview:imageView];
}
二、UIImage+ImageEffects的category
模糊效果
1.UIImage+ImageEffects是Accelerate框架中的内容
2.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];
}
- (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监听下载完毕后的事件
@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
- (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];
}
最新文章
- 从github拉取项目到myeclipse本地
- UDP传输
- python基础知识4——collection类——计数器,有序字典,默认字典,可命名元组,双向队列
- 2013 Visual Studio Magazine读者选择奖界面框架类获奖情况
- HTML5实战——svg学习
- Web开发-表单验证
- jQuery获取屏幕的宽度
- 27、Jquery 事件
- LInkedList集合练习
- OpenCV视屏跟踪
- 在VS工程中,添加c/c++工程中外部头文件及库
- VMware vSphere服务器虚拟化实验六 vCenter Server 添加储存
- android脚步---Itent.ACTION_PICK ,startActivityForResult
- vue组件之间的通信以及如何在父组件中调用子组件的方法和属性
- eclipse构建maven+scala+spark工程
- ASP.NET CORE MVC 2.0 项目中引用第三方DLL报错的解决办法 - InvalidOperationException: Cannot find compilation library location for package
- windows平台下cocos2d-x-3.0beta2创建新项目
- gitbash安装与使用
- [LeetCode] Encode N-ary Tree to Binary Tree 将N叉树编码为二叉树
- jumpserver安装
热门文章
- angular.element()的用法
- DELL平板如何安装WIN10系统-磁盘分区问题
- C#.NET常见问题(FAQ)-如何判断两个类是否相同类型
- Bridging and Bonding with CentOS 6.5
- Jquery 中的CheckBox、 RadioButton、 DropDownList的取值赋值
- MDX Step by Step 读书笔记(八) - Navigating Hierarchies 层次结构导航
- 很好的vmware目录
- 利用exif.js解决ios或Android手机上传竖拍照片旋转90度问题
- SQL Server中order by的使用,我们来填坑
- Porting .Net RSA xml keys to Java