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. Android基础问题汇总

    一.android:gravity 和android:layout_gravity的区别: android;gravity是自己的内容相对于自己的控件的位置,而android:layout_gravi ...

  2. C# 控制台窗口的显示与隐藏

    1. 定义一个Consolse帮助类,如下: /// <summary> /// 控制台帮助类 /// </summary> public static class Conso ...

  3. ecshop 函数列表大全

    lib_time.phpgmtime() P: 获得当前格林威治时间的时间戳 /$0server_timezone() P: 获得服务器的时区 /$0local_mktime($hour = NULL ...

  4. jquery text--val--html

    .html()用为读取和修改元素的HTML标签    对应js中的innerHTML .html()是用来读取元素的HTML内容(包括其Html标签),.html()方法使用在多个元素上时,只读取第一 ...

  5. Pintos-斯坦福大学操作系统Project详解-Project1

    转载请注明出处. 前言:  本实验来自斯坦福大学cs140课程,只限于教学用途,以下是他们对于Pintos系统的介绍:  Pintos is a simple operating system fra ...

  6. JavaScript拖拽

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <meta http-e ...

  7. configure: error: Cannot find libmysqlclient under /usr Note that the MySQL client library is not bundled anymore! 报错解决

    错误说明 今天在centos 6.3 64位版本上安装PHP5.4.3时在./configure 步骤的时候出现了下面错误configure: error: Cannot find libmysqlc ...

  8. Android Capability 细粒度的权限控制

    1. 传统的UID/GID,权限颗粒度太大 2. Capability: 细粒度的权限控制 3. 进程的Capability 4. 文件的Capability 5. 进程的Capability Bou ...

  9. #Leet Code# Divide Two Integers

    描述:不使用 * / % 完成除法操作.O(n)复杂度会超时,需要O(lg(n))复杂度. 代码: class Solution: # @return an integer def dividePos ...

  10. Global & Local Variable in Python

    Following code explain how 'global' works in the distinction of global variable and local variable. ...