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.

    }

  • 相关阅读:
    nginx 开机自动启动
    Linux 常用命令
    php中数组操作函数
    Windows系统下GitBash显示的中文乱码解决方案
    更改Git默认编辑器为notepad++
    【js】函数问题
    【JS】JavaScript中的参数传递
    Android基础整理之四大组件Activity
    关于BaseAdapter的使用及优化心得(一)
    使用MySQL Workbench建立数据库,建立新的表,向表中添加数据
  • 原文地址:https://www.cnblogs.com/wisejoker/p/3399838.html
Copyright © 2011-2022 走看看