//

//  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. php百度翻译类

    <?php // +---------------------------------------------------------------------- // | PHP MVC Fra ...

  2. ROS-TF-广播

    前言:将海龟的坐标系变换广播到TF. URDF文件的描述是在相对坐标上进行的,运动起来就需要考虑机器人各个连杆的相对位置关系.TF的诞生就是为了自动管理这些相对关系下的坐标变换的,而我们需要做的就是给 ...

  3. B - Guess a number!

    Problem description A TV show called "Guess a number!" is gathering popularity. The whole ...

  4. spring-boot结合mybatis-spring的一个例子

    首先spring-boot是用于简化配置的,具有可拔式组件的运用特点. 然后一下是spring-boot结合mybatis-spring的一个例子. 是一个maven项目 demo下载:http:// ...

  5. 批量插入 SqlBulkCopy的测试

    关于SqlBulkCopy的测试 最近要做.net关于sql大量插入,找到了sqlbulkcopy(自己google下,应该很多说明了)这个好东西,于是测试下性能,用了三个方法对比: 1)直接用ado ...

  6. 如何运用docker配合python开发

    在网络层,互联网提供所有应用程序都要使用的两种类型的服务,尽管目前理解这些服务的细节并不重要,但在所有TCP/IP概述中,都不能忽略他们: 无连接分组交付服务(Connectionless Packe ...

  7. 目录处理文件&链接命令

    一.目录处理文件 1.删除文件或目录 rm -rf [文件或目录]           //remove:删除文件或目录  -r:删除目录  -f:强制 2.复制文件或目录 cp [选项] [原文件或 ...

  8. 【seo】title / robots / description / canonical

    1.title title,就是浏览器上显示的那些内容,不仅用户能看到,也能被搜索引擎检索到(搜索引擎在抓取网页时,最先读取的就是网页标题,所以title是否正确设置极其重要. 1)title一般不超 ...

  9. css常用代码大全以及css兼容(转载)

    css常见的快捷开发代码汇总(长期更新),包括CSS3代码,有一些css效果很顽固,经常会一时找不出解决方案,网络上也有很多的工具和高手提供了具体的浏览器兼容代码,这个页面我今后会经常整理,希望能够帮 ...

  10. jquery ajax 全介绍

    下面是Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求 ...