iOS CoreImage图片处理动态渲染(滤镜)
//
// 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图片处理动态渲染(滤镜)的更多相关文章
- 从iOS的图片圆角想到渲染
圆角是一种很常见的视图效果,相比于直角,它更加柔和优美,易于接受.设置圆角会带来一定的性能损耗,如何提高性能是一个需要重点讨论的话题. 大家常见的圆角代码x.layer.cornerRadius = ...
- ios 开发视图界面动态渲染
#import "MyView.h" IB_DESIGNABLE @interface MyView () @property (nonatomic, strong) IBInsp ...
- iOS给图片添加滤镜&使用openGLES动态渲染图片
给图片增加滤镜有这两种方式: CoreImage / openGLES 下面先说明如何使用CoreImage给图片添加滤镜, 主要为以下步骤: #1.导入CIImage格式的原始图片 #2.创建CIF ...
- iOS CoreImage之滤镜简单使用
代码地址如下:http://www.demodashi.com/demo/11605.html 老骥伏枥,志在千里 前记 最近一直在研究图像处理方面,既上一篇iOS Quart2D绘图之UIImage ...
- [翻译] CRPixellatedView-用CIPixellate滤镜动态渲染UIView
CRPixellatedView-用CIPixellate滤镜动态渲染UIView https://github.com/chroman/CRPixellatedView 本人测试的效果: Usage ...
- iOS开发中的错误整理,启动图片设置了没有效果;单独创建xib需要注意的事项;图片取消系统渲染的快捷方式
一.启动图片设置了没有效果 解决方案:缓存啊!卸了程序重新安装吧!!!!! 二.单独创建xib需要注意的事项 三.图片取消系统渲染的快捷方式
- iOS 静态库和动态库的区别&静态库的生成
linux中静态库和动态库的区别 一.不同 库从本质上来说是一种可执行代码的二进制格式,可以被载入内存中执行.库分静态库和动态库两种. 1. 静态函数库 这类库的名字一般是libxxx.a:利用静态函 ...
- iOS 事件处理机制与图像渲染过程(转)
iOS 事件处理机制与图像渲染过程 iOS RunLoop都干了什么 iOS 为什么必须在主线程中操作UI 事件响应 CALayer CADisplayLink 和 NSTimer iOS 渲染过程 ...
- iOS 事件处理机制与图像渲染过程
Peter在开发公众号功能时触发了一个bug,导致群发错误.对此我们深表歉意,并果断开除了Peter.以下交回给正文时间: iOS 事件处理机制与图像渲染过程 iOS RunLoop都干了什么 iOS ...
随机推荐
- NOIP 2014 T2 联合权值 DFS
背景 NOIP2014提高组第二题 描述 无向连通图G有n个点,n-1条边.点从1到n依次编号,编号为i的点的权值为Wi ,每条边的长度均为1.图上两点(u, v)的距离定义为u点到v点的最短距离.对 ...
- 关于一些UI的插件(杂)
1.时间插件 //日期框 $('.date-picker').datepicker(); 2.checkbox 保存checkbox的值 // 组装选择的标签 var check = $(" ...
- Solr.NET快速入门(九)【二进制文档上传】【完】
二进制文档上传 SolrNet支持Solr"提取"功能(a.k.a. Solr"Cell")从二进制文档格式(如Word,PDF等)索引数据. 这里有一个简单的 ...
- maven nexus memory optimization
#链接地址:https://help.sonatype.com/repomanager3/system-requirements#filehandles While starting Nexus I ...
- [] == ![]为什么是true
我们先来考虑这个问题,console.log([] == false)会打印什么呢? 答案是true.为什么呢? 首先,因为当"=="号两边其中一个是布尔值的话,先把它转换为数字( ...
- Codeforces Round #454
Masha and Bears Tic-Tac-Toe Shockers Seating of Students Party Power Tower Reverses
- 洛谷P2391 白雪皑皑(并查集)
题目背景 “柴门闻犬吠,风雪夜归人”,冬天,不期而至.千里冰封,万里雪飘.空中刮起了鸭毛大雪.雪花纷纷,降落人间. 美能量星球(pty 在 spore 上的一个殖民地)上的人们被这美景所震撼.但是 p ...
- javascript 公历与农历相互转换工具类
/** * 公历[1900-1-31,2100-12-31]时间区间内的公历.农历互转 * @charset UTF-8 * @Author Jea杨(JJonline@JJonline.Cn) * ...
- error:informix Unable to load translation shared library 解决方案
错误:设置informix ODBC时“error:informix Unable to load translation shared library ” 原因 INFORMIXDIR环境变量在操作 ...
- 【Linux】SecureCRT中按退格键出现^H
分两步: ①SecureCRT上部的“选项”→“会话选项”→终端→仿真→映射键→其他映射→Backspace发送delete(B) 勾选中,确定 ②SecureCRT上部的“选项”→全局选项→常规→默 ...