locked
How to set manual focus for camera in MediaCapture

    Question

  • Hi,

    I am using the code below and it seems it is not working, no response.

    When I tap on the camera , there is no such box like this [  ]  being shown on the spot I tap.

    Am I doing wrong?  There is no Configure properties in MediaCapture.

    Please help. Thanks

    if (mediaManager == null)
                {
                    mediaManager = new Windows.Media.Capture.MediaCapture();
                
                    var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

                    await mediaManager.InitializeAsync(
                       new MediaCaptureInitializationSettings
                       {
                           VideoDeviceId = devices[1].Id
                       });
                  
                }


                if (mediaManager.MediaCaptureSettings.VideoDeviceId != "" && mediaManager.MediaCaptureSettings.AudioDeviceId != "")
                {
                    var cam = mediaManager.VideoDeviceController;

                    if (cam.FocusControl.Supported)
                    {
                        await cam.FocusControl.SetPresetAsync(Windows.Media.Devices.FocusPreset.Manual);
                        await cam.FocusControl.SetValueAsync(100);

                     
                    }               
                }         

            }

    Saturday, April 11, 2015 9:01 AM

All replies

  • How to disable the Manual Focus or use the default ?
    Sunday, April 12, 2015 1:52 PM
  • Hi FireDance,

    >>When I tap on the camera , there is no such box like this [  ]  being shown on the spot I tap.

    FocusControl has a method called FocusAsync(), just use that method the device will focus: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.media.devices.focuscontrol.focusasync.aspx

    await mediaManager.VideoDeviceController.FocusControl.SetPresetAsync(Windows.Media.Devices.FocusPreset.Manual);
    await mediaManager.VideoDeviceController.FocusControl.SetValueAsync(100);
    mediaManager.VideoDeviceController.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Manual, Value = 100, DisableDriverFallback = true });
    await mediaManager.VideoDeviceController.FocusControl.FocusAsync();

    >>How to disable the Manual Focus or use the default ?

    Just set FocusMode to Auto using FocusControl.Configure method:

    #FocusControl.Configure Method
    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.media.devices.focuscontrol.configure.aspx

    #FocusMode enumeration
    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.media.devices.focusmode.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 13, 2015 9:46 AM
    Moderator
  • Hi,

    I am using VS2013 Express.

    I import this:

    Windows.Media.Devices

    But I don't seems t find this Configure method !

    mediaManager.VideoDeviceController.FocusControl.Configure()

    mediaManager.VideoDeviceController.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Manual, Value = 100, DisableDriverFallback = true });

    What is the problem?

    Thanks

    Monday, April 13, 2015 1:36 PM
  • Hi,

    Can some1 help me? Why I could not get the Configure method as below?<br/>

    mediaManager.VideoDeviceController.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Manual, Value = 100, DisableDriverFallback = true });

    Thanks

    Thursday, April 16, 2015 1:44 PM
  • Hi,

    Can some1 help me? Why I could not get the Configure method as below?<br/>

    mediaManager.VideoDeviceController.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Manual, Value = 100, DisableDriverFallback = true });

    Thanks

    Hi FireDance,

    Sorry for the delay, I'm working on this and will come back if have any updates


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, April 26, 2015 8:04 AM
    Moderator
  • Hi,

    Can some1 help me? Why I could not get the Configure method as below?<br/>

    mediaManager.VideoDeviceController.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Manual, Value = 100, DisableDriverFallback = true });

    Thanks


    Hi FireDance,

    I'm using VS2013 Ultimate Update 4, the following sample worked well on my side:

    <StackPanel>
            <CaptureElement x:Name="captureElement" Width="300" Height="300" />
            <Button Content="Click" Click="Button_Click" />
        </StackPanel>

    DeviceInformation frontCamera, rearCamera;
    
    private async void Button_Click(object sender, RoutedEventArgs e)
    {
                MediaCapture _capture = new MediaCapture();
                var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
    
                foreach (var device in devices)
                {
                    switch (device.EnclosureLocation.Panel)
                    {
                        case Windows.Devices.Enumeration.Panel.Front:
                            frontCamera = device; //frontCamera is of type DeviceInformation
                            break;
                        case Windows.Devices.Enumeration.Panel.Back:
                            rearCamera = device; //rearCamera is of type DeviceInformation
                            break;
                        default:
                            //you can also check for Top, Left, right and Bottom
                            break;
                    }
                }
    
                await _capture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = frontCamera.Id });
    
                captureElement.Source = _capture;
                await _capture.StartPreviewAsync();
    
                _capture.VideoDeviceController.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Manual, Value = 100, DisableDriverFallback = true });
                await _capture.VideoDeviceController.FocusControl.FocusAsync();
    }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, April 26, 2015 12:29 PM
    Moderator
  • Hi, What does the value mean? when min is 0 and max is 1000 (Lumia ICON with 8.1), the 1000 means the focus is putting on infinite distance? and 100 means the distance is close to camera?

    Thanks!


    Te-Cheng Hsieh

    Thursday, May 14, 2015 5:12 AM
  • Also what does DisableDriverFallback mean?

    Te-Cheng Hsieh

    Thursday, May 14, 2015 5:13 AM