iOS GPUImage研究七:动态相册初探(水印)
前言:
其实,不仅仅是水印,包含一些3D立体相册的灵感。可以通过GPUImage来实现
试想一下,我们可以通过手机录制视频,然后能够实现自己添加特效,制作成动感影集,是不是很激动。
实现效果:
说明:
实现了一个简单地动画,逻辑是,A视图跟随B视图转动,但是A视图的尺寸仅仅被B视图包裹在内,随之变动。
其实很简单:
imageView1.frame = CGRectMake(imageView2.frame.origin.x+1, imageView2.frame.origin.y+1, imageView2.frame.size.width+1, imageView2.frame.size.height+1);imageView2.layer.transform = CATransform3DRotate(imageView2.layer.transform, M_PI/100, 0, 0 , 1);
一个简单地CATransform3D动画。
关于视频水印,请看上一篇博客
http://blog.csdn.net/xoxo_x/article/details/71055867
介绍一下:GPUImageUIElement
GPUImageUIElement 是一个输入类,可以将UIView属性的视图转为纹理,输入到输出源,例如:GPUImageView、GPUImageMovieWriter以及filter
其创建方式和对象方法:
// Initialization and teardown
- (id)initWithView:(UIView *)inputView;
- (id)initWithLayer:(CALayer *)inputLayer;
// Layer management
- (CGSize)layerSizeInPixels;
- (void)update;
- (void)updateUsingCurrentTime;
- (void)updateWithTimestamp:(CMTime)frameTime;
注意:
我们需要获取水印的动态,所以需要得到视频的时间戳,因此需要用到updateWithTimestamp这个函数。
如果我们不用的话,我们可以通过一个定时器来更新,但是获取当前时间的时间戳是麻烦的
监控视频时间:
这也是一个处理视频进度的一个回调。
GPUImageFilter* progressFilter = [[GPUImageFilter alloc] init];
[videoCamera addTarget:progressFilter];
[progressFilter addTarget:filter];//达到获取当前处理时间的时间戳的目的
[progressFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) {imageView1.frame = CGRectMake(imageView2.frame.origin.x+1, imageView2.frame.origin.y+1, imageView2.frame.size.width+1, imageView2.frame.size.height+1);imageView2.layer.transform = CATransform3DRotate(imageView2.layer.transform, M_PI/100, 0, 0 , 1);[strongSelf->pictureView updateWithTimestamp:time];}];
全部代码:
//
// ViewController.m
// WatermarkDemo
//
// Created by 冯士魁 on 2017/5/1.
// Copyright © 2017年 xoxo_x. All rights reserved.
//
/**在这里你会发现更多,好玩的事情* http://blog.csdn.net/xoxo_x/article***/#import "ViewController.h"
#import "GPUImage.h"@interface ViewController (){
// GPUImagePicture *pictureFile;GPUImageOutput<GPUImageInput> *filter;GPUImageVideoCamera *videoCamera;GPUImageView *filterView;GPUImageUIElement * pictureView;GPUImageMovie * movieFile;}@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];[self initGPUImageView];[self initFilter];[self initCamera];UIView *view = [[UIView alloc]initWithFrame:self.view.bounds];UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width/2, self.view.bounds.size.height/2)];imageView1.image = [UIImage imageNamed:@"美女1.jpg"];[view addSubview:imageView1];UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.bounds.size.width/4, self.view.bounds.size.height/4, self.view.bounds.size.width/2, self.view.bounds.size.height/2)];imageView2.image = [UIImage imageNamed:@"美女2.jpg"];[view addSubview:imageView2];pictureView = [[GPUImageUIElement alloc]initWithView:view];GPUImageFilter* progressFilter = [[GPUImageFilter alloc] init];[videoCamera addTarget:progressFilter];[progressFilter addTarget:filter];[pictureView addTarget:filter];[filter addTarget:filterView];[videoCamera startCameraCapture];__strong typeof(self) strongSelf = self;[progressFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) {imageView1.frame = CGRectMake(imageView2.frame.origin.x+1, imageView2.frame.origin.y+1, imageView2.frame.size.width+1, imageView2.frame.size.height+1);imageView2.layer.transform = CATransform3DRotate(imageView2.layer.transform, M_PI/100, 0, 0 , 1);[strongSelf->pictureView updateWithTimestamp:time];}];
}-(void)initGPUImageView{filterView = [[GPUImageView alloc] initWithFrame:self.view.frame];[self.view addSubview:filterView];
}-(void)initFilter{filter = [[GPUImageAlphaBlendFilter alloc] init];}-(void)initCamera{videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;videoCamera.horizontallyMirrorFrontFacingCamera = YES;
}
@end
欢迎打赏 – 打赏后、加好友哦 O(∩_∩)O哈哈~
iOS GPUImage研究七:动态相册初探(水印)相关推荐
- iOS GPUImage研究总结
小专栏:GPUImage的源码解读,带你打造一个实用框架 Part one: 关于GPUImage 这里直接引用官方描述: The GPUImage framework is a BSD-licens ...
- iOS GPUImage研究六:为视频添加图片水印
前言: 我们在前面已经做了关于.GPUImage导入方式.滤镜介绍.性能对比.图片处理.捕获照片处理.实时滤镜以及一个比较完整地Demo. 今天: 我们来给摄像头添加一个实时视频水印,很简单,大概有6 ...
- iOS GPUImage研究序一:内置滤镜
本片介绍关于GPUImage的125个内置过滤器:xoxo_x 著 本文参考:https://github.com/BradLarson/GPUImage#gpuimage 颜色调整 GPUImage ...
- iOS开发之GPUImage研究总结,视频、图片等添加滤镜(转载)
转载自:https://blog.csdn.net/Xoxo_x/article/details/52695032(非常感谢!) Part one: 关于GPUImage 这里直接引用官方描述: Th ...
- iOS大典之动态相册
简单动态相册, 相册功能很实用, 属于必须掌握的范畴. 准备: 图片若干张; 创建UIView 创建UIViewController 实现: 点击 start按钮, 开始动态显示 点击 stop按钮, ...
- 基于人工智能智商研究的智能定律初探
什么是智能和意识一直是智能科学领域最基础也是最具有争议的问题,2014年以来,我们在对人机通用智能发展水平的进行研究时提出了标准智能模型,统一描述人和智能机器的特征.在这个研究的基础上,2020年5月 ...
- Unity与IOS交互,调用相机相册,兼容ipad
IOS篇 在处理unity和ios的时候,除了对oc不太习惯以外,还有就是iphone和ipad有些方法需要做区别.比如通用的弹窗方法不用,以及ipad上打开相册竟然可以支持显示的相册不是全屏了!好吧 ...
- 抖音上很火的动态相册(末尾附加下载地址)
抖音上很火的动态相册(末尾附加下载地址) 一.相册简介 二.部分代码简介及其运用 三.修改指南 四.总结及其获取方式 一.相册简介 1.首先该相册是用大家熟悉的HTML.CSS在此基础之上调用了几个J ...
- 使用YOLO Core ML模型构建对象检测iOS应用(七)
目录 在我们的应用程序中添加模型 在捕获的视频帧上运行目标检测 绘制边界框 实际应用 下一步? 总目录 将ONNX对象检测模型转换为iOS Core ML(一) 解码Core ML YOLO对象检测器 ...
最新文章
- python学习(一)-----数据结构和算法----序列和字典的基本用法
- 无法解析的外部符号 class boost::system::error_category const __cdecl boost::system::system_category(void)
- 基于VTK User Guide和VTK Textbook学习
- 解析oracle的rownum
- Golang 的跨平台交叉编译浅析
- 2003年以来网页尺寸增长3倍
- 论文浅尝 | 用异源监督进行关系抽取:一种表示学习方法
- c#中字符串截取使用的方法
- 分布式系统下数据一致性
- html分页过多,实现分页处理,固定分页数目,数目始终中间显示,自定义分页跳转(在结尾的代码)
- Ubuntu 部分截图
- windows7系统损坏修复_火绒安全警报:微软发布高危漏洞补丁 火绒“漏洞修复”模块已完成升级...
- PPT - 双屏幕情况下,如何设置 PPT 不在主屏幕显示问题?
- 百度搜索移动端流量词热度统计方法
- c语言统计大小写字母 空格 和数字个数,C++统计中英文大小写字母、数字、空格及其他字符个数的方法...
- 使用imagemagic生成动态图片GIF
- [moses笔记]编译含有nplm的moses解码器
- PG主程序模块(Main)——boot模式
- linux脚本简单定时,shell之定时周期性执行脚本的方法示例
- 人工智能的未来:趋势和对软件工程师的启示