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.

    }

  • 相关阅读:
    网络流
    随机化
    sw抄来的主席树
    牛客SQL题解-统计各个部门的工资记录数
    牛客SQL题解-查找所有员工自入职以来的薪水涨幅情况
    牛客SQL题解-查找薪水排名第二多的员工编号emp_no、薪水salary、last_name以及first_name,不能使用order by完成
    牛客SQL题解-查找所有员工的last_name和first_name以及对应的dept_name,也包括暂时没有分配部门的员工
    牛客SQL题解-获取薪水第二多的员工的emp_no以及其对应的薪水salary
    牛客SQL题解-统计出各个title类型对应的员工薪水对应的平均工资avg
    牛客SQL题解-查找employees表所有emp_no为奇数,且last_name不为Mary的员工信息,并按照hire_date逆序排列
  • 原文地址:https://www.cnblogs.com/wisejoker/p/3399838.html
Copyright © 2011-2022 走看看