博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
<iOS4>Switching between front an…
阅读量:4071 次
发布时间:2019-05-25

本文共 1301 字,大约阅读时间需要 4 分钟。

#import <avfoundation avfoundation.h="">


// Switching between front and back cameras


- (AVCaptureDevice *)cameraWithPosition:(AVCaptureDevicePosition)position

{

    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];

    for ( AVCaptureDevice *device in devices )

        if ( device.position == position )

            return device;

    return nil;

}


- (void)swapFrontAndBackCameras {

    // Assume the session is already running

    

    NSArray *inputs = self.session.inputs;

    for ( AVCaptureDeviceInput *input in inputs ) {

        AVCaptureDevice *device = input.device;

        if ( [device hasMediaType:AVMediaTypeVideo] ) {

            AVCaptureDevicePosition position = device.position;

            AVCaptureDevice *newCamera = nil;

            AVCaptureDeviceInput *newInput = nil;

            

            if (position == AVCaptureDevicePositionFront)

                newCamera = [self cameraWithPosition:AVCaptureDevicePositionBack];

                else

                    newCamera = [self cameraWithPosition:AVCaptureDevicePositionFront];

                    newInput = [AVCaptureDeviceInput deviceInputWithDevice:newCamera error:nil];

                    

                    // beginConfiguration ensures that pending changes are not applied immediately

                    [self.session beginConfiguration];

            

            [self.session removeInput:input];

            [self.session addInput:newInput];

            

            // Changes take effect once the outermost commitConfiguration is invoked.

            [self.session commitConfiguration];

            break;

        }

   

}

</avfoundation>

转载地址:http://qjeji.baihongyu.com/

你可能感兴趣的文章
《计算机网络》第五章 运输层 ——TCP和UDP 可靠传输原理 TCP流量控制 拥塞控制 连接管理
查看>>
堆排序完整版,含注释
查看>>
二叉树深度优先遍历和广度优先遍历
查看>>
生产者消费者模型,循环队列实现
查看>>
PostgreSQL代码分析,查询优化部分,process_duplicate_ors
查看>>
PostgreSQL代码分析,查询优化部分,canonicalize_qual
查看>>
PostgreSQL代码分析,查询优化部分,pull_ands()和pull_ors()
查看>>
ORACLE权限管理调研笔记
查看>>
移进规约冲突一例
查看>>
IA32时钟周期的一些内容
查看>>
SM2椭圆曲线公钥密码算法
查看>>
获得github工程中的一个文件夹的方法
查看>>
《PostgreSQL技术内幕:查询优化深度探索》养成记
查看>>
PostgreSQL查询优化器详解之逻辑优化篇
查看>>
STM32中assert_param的使用
查看>>
C语言中的 (void*)0 与 (void)0
查看>>
vu 是什么
查看>>
io口的作用
查看>>
IO口的作用
查看>>
UIView的使用setNeedsDisplay
查看>>