简体   繁体   中英

MediaCapture change camera focus(WP8.1 and WinRt8.1)

I use MediaCapture like this

MediaCapture _capture = new MediaCapture();
await _capture.InitializeAsync();
await _capture.StartPreviewAsync();

and camera work. But I need to change camera focus from code. Did you know how to do this?

MediaCapture class has a property VideoDeviceController which returns device controller .

You will find there all the properties of your camera along with focus and FocusControl . I've managed to change focus like this:

// first set mode to manual
await _capture.VideoDeviceController.FocusControl.SetPresetAsync(Windows.Media.Devices.FocusPreset.Manual);
await _capture.VideoDeviceController.FocusControl.SetValueAsync(100);
// but those two above are deprecated - it will work but I would advise to do it:
_capture.VideoDeviceController.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Manual, Value = 100, DisableDriverFallback = true });
await _capture.VideoDeviceController.FocusControl.FocusAsync();

You can focus using this line

_mediaCapture.VideoDeviceController.FocusControl.FocusAsync();

call this on a event, like on CaptureElement tapped event or set a focus button and call this when focus button is clicked or call it just before capturing the photo so the photo is captured after focusing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM