美文网首页
iOS 相机超广角0.5x,1x,2x

iOS 相机超广角0.5x,1x,2x

作者: Mr_fei | 来源:发表于2023-05-14 15:21 被阅读0次

    需求:使用相机的广角功能,0.5x,1x,2x
    代码:

    AVCaptureDevice *backFacingCamera = nil;
        if (@available(iOS 13.0, *)) {
            AVCaptureDeviceDiscoverySession * session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInTripleCamera, AVCaptureDeviceTypeBuiltInTrueDepthCamera, AVCaptureDeviceTypeBuiltInDualWideCamera, AVCaptureDeviceTypeBuiltInDualCamera, AVCaptureDeviceTypeBuiltInUltraWideCamera, AVCaptureDeviceTypeBuiltInTelephotoCamera, AVCaptureDeviceTypeBuiltInWideAngleCamera] mediaType:AVMediaTypeVideo position:currentCameraPosition];
            
            NSArray *devices = session.devices;
            for (AVCaptureDevice *device in devices) {
                //AVCaptureDeviceTypeBuiltInDualWideCamera
                if ([device position] == currentCameraPosition) {
                    backFacingCamera = device;
                    break;
                }
                NSLog(@"=======%@",device.deviceType);
            }
            
          NSArray *array = backFacingCamera.virtualDeviceSwitchOverVideoZoomFactors;
            NSLog(@"======%@  %f",array, backFacingCamera.dualCameraSwitchOverVideoZoomFactor);
            
        } else {
            NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
            for (AVCaptureDevice *device in devices)
            {
                if ([device position] == currentCameraPosition)
                {
                    backFacingCamera = device;
                }
            }
        }
    

    设置焦距

    [_captureSession beginConfiguration];
    [backFacingCamera setVideoZoomFactor:1];
     [_captureSession commitConfiguration];
    

    相关文章

      网友评论

          本文标题:iOS 相机超广角0.5x,1x,2x

          本文链接:https://www.haomeiwen.com/subject/hqepsdtx.html