zoukankan      html  css  js  c++  java
  • 用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.

    }

  • 相关阅读:
    Hadoop集群VSFTP和SecureCRT安装配置
    Hadoop集群完全分布式坏境搭建
    Hadoop集群坏境搭建配置
    Hadoop集群坏境CentOS安装
    Pr视频剪辑基础技巧学习
    SAN和NAS之间的基本区别
    原始容量、可用容量和有效容量的区别
    解释一下什么是网盘与云盘
    纠错技术之FEC(向前纠错)
    分布式存储的冗余类型(N+2:1)
  • 原文地址:https://www.cnblogs.com/wisejoker/p/3399838.html
Copyright © 2011-2022 走看看