//

//  ViewController.m

//  CoreImageOfDong

//

//  Created by Dong on 15/6/30.

//  Copyright (c) 2015年 xindong. All rights reserved.

//

#import "ViewController.h"

#import <GLKit/GLKit.h>
// 须要导入此库

@interface ViewController ()

@property (nonatomic,
strong)
GLKView *glkView;
//渲染用的buffer视图(类似流媒体,实时改变)

@property (nonatomic, strong) CIFilter *filter;

@property (nonatomic, strong) CIImage *ciImage;

@property (nonatomic, strong) CIContext *ciContext;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

UIImage *showImage = [UIImage imageNamed:@"demo1.jpg"];

CGRect rect = CGRectMake(0, 0, showImage.size.width, showImage.size.height);

// 获取OpenGLES渲染的上下文

EAGLContext *eagContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

// 创建出渲染的buffer

self.glkView = [[GLKView alloc] initWithFrame:rect context:eagContext];

[self.glkView bindDrawable];
// 绑定绘制,否则刚開始会黑屏

[self.view addSubview:self.glkView];

// 创建出CoreImage用的上下文

self.ciContext = [CIContext contextWithEAGLContext:eagContext options:@{kCIContextWorkingColorSpace : [NSNull null]}];

// CoreImage相关设置

self.ciImage = [[CIImage alloc] initWithImage:showImage];

self.filter = [CIFilter filterWithName:@"CISepiaTone"];

[self.filter setValue:self.ciImage forKey:kCIInputImageKey];

[self.filter setValue:@(0) forKey:kCIInputIntensityKey];

// 開始渲染

[self.ciContext drawImage:[self.filter valueForKey:kCIOutputImageKey] inRect:CGRectMake(0, 0, self.glkView.drawableWidth, self.glkView.drawableHeight) fromRect:[self.ciImage
extent]];

[self.glkView display];

//
动态渲染

UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(30, 500, 200, 10)];

slider.minimumValue = 0.f;

slider.maximumValue = 10.f;

[slider addTarget:self action:@selector(changeColorValue:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:slider];

}

- (void)changeColorValue:(UISlider *)slider

{

[self.filter setValue:self.ciImage forKey:kCIInputImageKey];

[self.filter setValue:@(slider.value) forKey:kCIInputIntensityKey];

// 開始渲染

[self.ciContext drawImage:[self.filter valueForKey:kCIOutputImageKey] inRect:CGRectMake(0, 0, self.glkView.drawableWidth, self.glkView.drawableHeight) fromRect:[self.ciImage
extent]];

[self.glkView display];

}

iOS CoreImage图片处理动态渲染(滤镜)的更多相关文章

  1. 从iOS的图片圆角想到渲染

    圆角是一种很常见的视图效果,相比于直角,它更加柔和优美,易于接受.设置圆角会带来一定的性能损耗,如何提高性能是一个需要重点讨论的话题. 大家常见的圆角代码x.layer.cornerRadius = ...

  2. ios 开发视图界面动态渲染

    #import "MyView.h" IB_DESIGNABLE @interface MyView () @property (nonatomic, strong) IBInsp ...

  3. iOS给图片添加滤镜&使用openGLES动态渲染图片

    给图片增加滤镜有这两种方式: CoreImage / openGLES 下面先说明如何使用CoreImage给图片添加滤镜, 主要为以下步骤: #1.导入CIImage格式的原始图片 #2.创建CIF ...

  4. iOS CoreImage之滤镜简单使用

    代码地址如下:http://www.demodashi.com/demo/11605.html 老骥伏枥,志在千里 前记 最近一直在研究图像处理方面,既上一篇iOS Quart2D绘图之UIImage ...

  5. [翻译] CRPixellatedView-用CIPixellate滤镜动态渲染UIView

    CRPixellatedView-用CIPixellate滤镜动态渲染UIView https://github.com/chroman/CRPixellatedView 本人测试的效果: Usage ...

  6. iOS开发中的错误整理,启动图片设置了没有效果;单独创建xib需要注意的事项;图片取消系统渲染的快捷方式

    一.启动图片设置了没有效果 解决方案:缓存啊!卸了程序重新安装吧!!!!! 二.单独创建xib需要注意的事项 三.图片取消系统渲染的快捷方式

  7. iOS 静态库和动态库的区别&静态库的生成

    linux中静态库和动态库的区别 一.不同 库从本质上来说是一种可执行代码的二进制格式,可以被载入内存中执行.库分静态库和动态库两种. 1. 静态函数库 这类库的名字一般是libxxx.a:利用静态函 ...

  8. iOS 事件处理机制与图像渲染过程(转)

    iOS 事件处理机制与图像渲染过程 iOS RunLoop都干了什么 iOS 为什么必须在主线程中操作UI 事件响应 CALayer CADisplayLink 和 NSTimer iOS 渲染过程 ...

  9. iOS 事件处理机制与图像渲染过程

    Peter在开发公众号功能时触发了一个bug,导致群发错误.对此我们深表歉意,并果断开除了Peter.以下交回给正文时间: iOS 事件处理机制与图像渲染过程 iOS RunLoop都干了什么 iOS ...

随机推荐

  1. IPv6通讯原理(1) - 不能忽略的网卡启动过程

    本文主题:通过抓包分析,深入观察网卡启动过程的每个步骤,从而逐步掌握通讯原理.

  2. SQLServer 行转列,统计,二次分组

    create table test (   bizdate datetime, --日期   classes varchar(50), --班次 '白班' 或 '夜班'   qty int --产量 ...

  3. 使用WebGL + Three.js制作动画场景

    使用WebGL + Three.js制作动画场景 3D图像,技术,打造产品,还有互联网:这些只是我爱好的一小部分. 现在,感谢WebGL的出现-一个新的JavaScriptAPI,它可以在不依赖任何插 ...

  4. RN配置

    Write by lz: 详细参考官方网址: http://reactnative.cn/docs/0.43/getting-started.html#content 若是无法安装 Chocolate ...

  5. linq.sort

    reflections.Sort(delegate(ReflectionEntity a, ReflectionEntity b) { if (a.CreatedTime < b.Created ...

  6. div 内容水平垂直居中

    对于前端布局来说.总有一些图片水平垂直居中老是不好看,影响整体美观,百度一大堆各种自适应方法,终于找到了一种比较简单,适用于所有场景的方法.. 1.对于布局来说.一个div搞定. <div id ...

  7. linux抓包命令-tcpdump命令详解

    最近调试支付接口的时候,遇到了一个奇怪的问题:我按照支付接口文档,对接支付通道,当消费业务正常后,调试查余和冲正的时候,支付通道的对接技术告诉我,系统没有我们支付系统的请求报文,数据库和日志中都没有, ...

  8. bootstrap3-dialog:更强大、更灵活的模态框

    用过bootstrap框架的同学们都知道,bootstrap自带的模态框用起来很不灵活,可谓鸡肋的很.但nakupanda开源作者封装了一个更强大.更灵活的模态框——bootstrap3-dialog ...

  9. RxSwift源码与模式分析一:基本类

    封装.变换与处理 // Represents a push style sequence. public protocol ObservableType : ObservableConvertible ...

  10. Kafka学习笔记(3)----Kafka的数据复制(Replica)与Failover

    1. CAP理论 1.1 Cosistency(一致性) 通过某个节点的写操作结果对后面通过其他节点的读操作可见. 如果更新数据后,并发访问的情况下可立即感知该更新,称为强一致性 如果允许之后部分或全 ...