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 ...
随机推荐
- Java Socket通讯---网络基础
java socket 通讯 参考慕课网:http://www.imooc.com/learn/161 一.网络基础知识 1.1 通讯示意图 1.2 TCP/IP协议 TCP/IP是世界上应用最为广泛 ...
- C#中的值类型、引用类型,代码告诉你他是什么类型。
C#代码告诉你这是什么类型. using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- 利用jquery的ajaxPrefilter阻止重复发送请求
利用jquery的ajaxPrefilter阻止重复发送请求 (function ($) { var pendingRequests = {}; // 所有ajax请求的通用前置filter $.aj ...
- 【Oracle】glogin.sql脚本模板
[root@localhost ~]# su - oracle [oracle@localhost ~]$ vi $ORACLE_HOME/sqlplus/admin/glogin.sql defin ...
- C# 6.0新加特性
1.自动属性的增强 1.1.自动属性初始化 (Initializers for auto-properties) C#4.0下的果断实现不了的. C#6.0中自动属性的初始化方式 只要接触过C#的肯定 ...
- 使用Eric构建Caffe应用程序-Baby年龄识别
训练好的Caffe网络结构,可以固定下来,直接载入程序作为数据库接口使用.本文使用Eric构建运行于Python环境下的图片识别应用程序,因为Eric使用QT作为GUI,且有Python的接口,可直接 ...
- ios 编译版本 最低版本 运行版本 动态链接库
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) 运行环境判断: #if __IPHONE_OS_VERSION_ ...
- C# 把对象序列化 JSON 字符串 和把JSON字符串还原为对象
/// <summary> /// 把对象序列化 JSON 字符串 /// </summary> /// <typeparam name="T"> ...
- python入门基础知识
1.python环境的安装 python2 python3 安装后添加环境变量 2.编码 最早编码ASCII码,主要有英文,数字,字符.一字节(byte),八位(bit),代表一个字符 unicode ...
- JS 蓝球弹起的高度 100 米 第几次高度小于1米
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...