Forum Xamarin.iOS

AvCaptureDevice -- Zoom not working

TimHawkinsTimHawkins USMember ✭✭
edited November 2017 in Xamarin.iOS

I am trying to increase the zoom of the camera to its max level in my application.

However even after setting the device VideoZoomFactor to its max it still manages to remain the same on the screen.

Below is my implementation

void Initialize()
{

    var videoDevs = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video);
    var position = (cameraOptions == CameraOptions.Front) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back;
    var device = videoDevs.FirstOrDefault(d => d.Position == position);            

    device.LockForConfiguration(out error);
    if (error == null)
    {
            device.VideoZoomFactor = device.ActiveFormat.VideoMaxZoomFactor;
    }
    device.UnlockForConfiguration();

    while(device.RampingVideoZoom == true)
    {
            Console.WriteLine("Zooming camera"); //This line is never written
    }
    Console.WriteLine("Zoom Factor");
    Console.WriteLine(device.VideoZoomFactor); //This returns 16

    Console.WriteLine("Current Format");
    Console.WriteLine(device.ActiveFormat);
}

The last Console WriteLine returns:

<AVCaptureDeviceFormat: 0x1c48049a0 'vide'/'420v' 1920x1080, { 3- 30 fps}, HRSI:4096x2304, fov:59.680, supports vis, max zoom:16.00 (upscales @1.94), AF System:2, ISO:22.0-704.0, SS:0.000005-0.333333>

So I know it is possible to zoom but it is not working.

Any suggestions?

Answers

  • LGFoxLGFox USMember
    edited August 2018

    Try the same but after you add the device to a session:

    AVCaptureDeviceInput.FromDevice(device); // Created AVCaptureDeviceInput from the device instance
    session.AddInput(input); // Added to AVCaptureSession
    

    Also instead:

    if (error == null)
        {
            device.VideoZoomFactor = device.ActiveFormat.VideoMaxZoomFactor;
        }
    

    You can write like this:

    if (device.LockForConfiguration(out error))
        {
            device.VideoZoomFactor = device.ActiveFormat.VideoMaxZoomFactor;
        }
    else
        {
            Console.WriteLine($"Error occured: {error.Description}");
        }
    
Sign In or Register to comment.