用GPUImage开启相机并且开启滤镜效果
GPUImage提供了GPUImageVideoCamera这么一个类,它的对象能够调用摄像头,并且加上滤镜的效果。
//init VideoCamera
//这里的两个参数可以设定拍摄录像的像素,还有拍摄录像的前后摄像头。不过要注意的是前后摄像头对像素的要求不同,1080P的录像就不可能在钱摄像头完成了哈
videoCamera = [[GPUImageVideoCameraalloc] initWithSessionPreset:AVCaptureSessionPreset640x480cameraPosition:AVCaptureDevicePositionBack];
//这个参数是确定摄像的方向
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
//开始摄像。这个方法可以放在任意地方,只要运行了这个方法就开始摄像了
[videoCamerastartCameraCapture];
这些只是开始摄像的初始化工作,如果没有图像输出那么也是没有用的哈(虽然StartCameraCapture的作用是开启摄像头,但是如果摄像头上的图像没有传递到屏幕上那么是没有图像的)
//把滤镜效果加给摄像头
[videoCameraaddTarget:testFilter];
//把摄像头上的图像给GPUImageView显示出来
[testFilteraddTarget:imageView];
在这里的TestFilter已经是初始化过了的滤镜效果。
这样就可以成功摄像了
//关闭摄像头
[videoCamerastopCameraCapture];
关闭摄像头也很简单,就不多说了哈
还有一个最重要的地方,开启摄像头需要完成以下接口才能正常运行:
#pragma mark - vidoe camera
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
// Map UIDeviceOrientation to UIInterfaceOrientation.
UIInterfaceOrientation orient = UIInterfaceOrientationPortrait;
switch ([[UIDevicecurrentDevice] orientation])
{
caseUIDeviceOrientationLandscapeLeft:
orient = UIInterfaceOrientationLandscapeLeft;
break;
caseUIDeviceOrientationLandscapeRight:
orient = UIInterfaceOrientationLandscapeRight;
break;
caseUIDeviceOrientationPortrait:
orient = UIInterfaceOrientationPortrait;
break;
caseUIDeviceOrientationPortraitUpsideDown:
orient = UIInterfaceOrientationPortraitUpsideDown;
break;
caseUIDeviceOrientationFaceUp:
caseUIDeviceOrientationFaceDown:
caseUIDeviceOrientationUnknown:
// When in doubt, stay the same.
orient = fromInterfaceOrientation;
break;
}
videoCamera.outputImageOrientation = orient;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
returnYES; // Support all orientations.
}
用GPUImage开启相机并且开启滤镜效果的更多相关文章
- Android开启相机预览获取Yuv视频流数据
自定义SurfaceView 主要步骤: 实现SurfaceHolder.Callback接口,创建SurfaceView的生命周期 实现Camera.PreviewCallback接口,创建预览回调 ...
- linux下查看php-fpm是否开启以及如何开启
对于linux接触很少,对于命令很不熟,今天发现之前部署的站点无法访问了,就想可能是nginx或者php-fpm没有开启. 所以这里记录linux下查看php-fpm是否开启以及如何开启(nginx也 ...
- Android 7.0 之后相机/文件读写等权限获取方式改变,导致开启相机闪退
在 Android 7.0 之前 Google 提供的动态申请权限的 API,可以调用相机拍照,访问SDcard等操作都只需要申请对应的权限,如下: <uses-permission andro ...
- ios7.1后setting中没有开启相机服务应用程序相机预览黑屏问题
if ( [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){ ...
- shopnc怎么开启伪静态 shopnc开启伪静态的方法
最近要给一个shopnc网站开启伪静态,用的是shopnc b2b2c,在网上搜索了好多shopnc开启伪静态的方法,但都是针对shaopnc c2c的,没有关于shopnc b2b2c的,最后终于找 ...
- ios简单实现如果没有开启定位,提示开启系统软件定位功能
if([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == ...
- macOS apache配置及开启虚拟服务器的开启,apache开启重写模式
今天把自己的mac系统升到最新版,但是,apache却不能用了,因为mac上的apache是系统自带的,因为是mac目前的最新系统,所以出现了好多问题,整理了一下午也没有啥进展,最后还是把原来的在云盘 ...
- fedora 开启 apache 并 开启目录浏览模式
在内网中 暂时需要一台 文件 服务器,所以准备安装一台 http服务器并开启目录访问权限.这次使用 apache 在 fedora 28 机器上: 因为 fedora 28 已经包含 httpd 软件 ...
- Android -- service的开启方式, start开启和绑定开启服务,调用服务的的方法, aidl调用远程服务
1. 概述 bindService() 绑定服务 可以得到服务的代理人对象,间接调用服务里面的方法. 绑定服务: 间接调用服务里面的方法. 如果调用者activity被销毁了, ...
随机推荐
- iOS pop使用通知传值
iOS pop回父级页面,使用通知传值 输入所要发送的信息 ,同时将label的值通过button方法调用传递, - (IBAction)buttonClick:(id)sender { //添加 字 ...
- ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)
题目描述 We know thatIvan gives Saya three problems to solve (Problem F), and this is the firstproblem. ...
- (转)应用内存优化之OnLowMemory&OnTrimMemory
1.应用内存onLowMemory& onTrimMemory优化 onLowMemory& onTrimMemory简介:OnLowMemory是Android提供的API,在系统内 ...
- 开发错误日志之No matching bean of type [xxx] found for dependency
No matching bean of type [org.springframework.data.mongodb.core.MongoTemplate] found for dependency ...
- jQuery 鼠标滑过及选中一行效果
/******* 表格效果 ********/ $("#gird_tbl tbody tr").live('mouseover', function () { $(this).ad ...
- C#编写自动关机程序复习的知识
首先一个程序第一要素是logo 在设置里面可以设置程序图标,在ICON里设置. ICON图标可以在网上下载. 这些都是表面功夫 程序中涉及到Buton.Label.Timer.Notiflcon控件 ...
- 2016022606 - redis事务
Redis事务 Redis事务让一组命令在单个步骤执行.事务中有两个属性,说明如下: 1.在一个事务中的所有命令按顺序执行作为单个隔离操作.通过另一个客户端发出的请求在Redis的事务的过程中执行,这 ...
- 源码编译基于Android平台的XBMC笔记
参考官方网站:https://github.com/xbmc/xbmc/blob/master/docs/README.android 1. 编译主机系统 Ubuntu (12.04) 64Bit ...
- caffe---测试模型分类结果并输出(python )
当训练好一个model之后,我们通常会根据这个model最终的loss和在验证集上的accuracy来判断它的好坏.但是,对于分类问题,我们如果只是知道整体的分类正确率 显然还不够,所以只有知道模型对 ...
- SpringSecurity数据库中存储用户、角色、资源
这几天项目中用到了SpringSecurity做登陆安全.所以在这写一下也许可以帮助一下其他人,自己也熟悉一下 SpringSecurity配置文件如下: <beans:beans xmlns= ...