iOS 相机超广角0.5x,1x,2x
2023-05-14 本文已影响0人
Mr_fei
需求:使用相机的广角功能,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];