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开启相机并且开启滤镜效果的更多相关文章

  1. Android开启相机预览获取Yuv视频流数据

    自定义SurfaceView 主要步骤: 实现SurfaceHolder.Callback接口,创建SurfaceView的生命周期 实现Camera.PreviewCallback接口,创建预览回调 ...

  2. linux下查看php-fpm是否开启以及如何开启

    对于linux接触很少,对于命令很不熟,今天发现之前部署的站点无法访问了,就想可能是nginx或者php-fpm没有开启. 所以这里记录linux下查看php-fpm是否开启以及如何开启(nginx也 ...

  3. Android 7.0 之后相机/文件读写等权限获取方式改变,导致开启相机闪退

    在 Android 7.0 之前 Google 提供的动态申请权限的 API,可以调用相机拍照,访问SDcard等操作都只需要申请对应的权限,如下: <uses-permission andro ...

  4. ios7.1后setting中没有开启相机服务应用程序相机预览黑屏问题

    if ( [[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){                               ...

  5. shopnc怎么开启伪静态 shopnc开启伪静态的方法

    最近要给一个shopnc网站开启伪静态,用的是shopnc b2b2c,在网上搜索了好多shopnc开启伪静态的方法,但都是针对shaopnc c2c的,没有关于shopnc b2b2c的,最后终于找 ...

  6. ios简单实现如果没有开启定位,提示开启系统软件定位功能

    if([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == ...

  7. macOS apache配置及开启虚拟服务器的开启,apache开启重写模式

    今天把自己的mac系统升到最新版,但是,apache却不能用了,因为mac上的apache是系统自带的,因为是mac目前的最新系统,所以出现了好多问题,整理了一下午也没有啥进展,最后还是把原来的在云盘 ...

  8. fedora 开启 apache 并 开启目录浏览模式

    在内网中 暂时需要一台 文件 服务器,所以准备安装一台 http服务器并开启目录访问权限.这次使用 apache 在 fedora 28 机器上: 因为 fedora 28 已经包含 httpd 软件 ...

  9. Android -- service的开启方式, start开启和绑定开启服务,调用服务的的方法, aidl调用远程服务

    1. 概述 bindService() 绑定服务  可以得到服务的代理人对象,间接调用服务里面的方法. 绑定服务: 间接调用服务里面的方法.           如果调用者activity被销毁了, ...

随机推荐

  1. hibernate - 何时关闭数据库

    ref: http://www.coderanch.com/t/637103/ORM/databases/close-database-connection-hibernate 我上这个问题, 原因是 ...

  2. linux下安装多个mysql实例(摘自国外:How to create multiple mysql instance in CentOS 6.4 and Red Hat 6.4)

    How to create multiple mysql instance in CentOS 6.4 and Red Hat 6.4 from:http://sharadchhetri.com/20 ...

  3. swift 赋值判断

    . var name:String? = "Wing" var geting = "Hello!" if let thisname = name{ geting ...

  4. 查看Safari和钥匙串中的密码

    Safari Safari的同步书签功能很棒,还可以看到其他设备没关掉的网页.为了省时间,一些经常进的网站,比如博客,邮箱等,我都会选择让Safari保存密码,还使用iCloud同步!因为一直很放心苹 ...

  5. iOS 获取URL中的参数

    - (NSString *)getParamByName:(NSString *)name URLString:(NSString *)url { NSError *error; NSString * ...

  6. gif图简介

    多媒体教程 - GIF 图 GIF 是在 Web 上使用的主要图像格式之一. 本文详细讲解了 GIF 图像的特性和使用技巧. 理解图像格式 无论是 HTML 还是 XHTML 都没有规定图像的官方格式 ...

  7. Linq XML

    写得比较啰嗦,自己记载备用   1 public class XmlFunction   2     {   3         private static XDocument _doc = new ...

  8. Windows phone 之 UserControl的应用

    一.新建一个UserControl.xaml页面  MyUserControl.xaml 添加代码如下: <UserControl x:Class="bodypicture.MyUse ...

  9. 【实习记】2014-08-20实习的mini项目总结

        实习项目总结文档 项目介绍 项目逻辑很简单,只有几个页面,只能登录,查看,支付和退款.主要作用是熟悉C++的cgi的web服务开发方式. 项目页面截图 图一:登录页面 图二:买家查看 图三:买 ...

  10. C#程序中:如何删除xml文件中的节点、元素。

    C#中动态的清理xml文件中的垃圾信息是程序员必会的哦.这就像数据库一样,不会清理数据怎么可以呢?其实xml文件就可以用作一个小的数据库,存储一些简单的信息.所以,用C#程序实现xml文件的增.删.改 ...