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.

    }

  • 相关阅读:
    JAVA中的BIO,NIO,AIO
    JAVA通过信号量避免死锁
    java死锁
    ConcurrentHashMap并不是完全的线程安全
    【技术学习】Understand Exit Codes of Docker
    【技术学习】centos7 firewall
    【现场问题】Linux Cache过大问题排查
    【技术学习】postgresql学习笔记--基础篇
    【技术学习】postgresql学习笔记--基础篇
    【监控脚本】利用selenium自动化测试样例一
  • 原文地址:https://www.cnblogs.com/wisejoker/p/3399838.html
Copyright © 2011-2022 走看看