好的,我的问题很简单.
我已经设法打开闪光灯(并保持打开).
但是,我仍然不确定如何关闭它(笑).
这是我的代码:
var sensorLocation = CameraSensorLocation.Back; try { // get the AudioViceoCaptureDevice var avDevice = await AudioVideoCaptureDevice.OpenAsync(sensorLocation,AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First()); // turn flashlight on var supportedCameraModes = AudioVideoCaptureDevice .GetSupportedPropertyValues(sensorLocation,KNownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { avDevice.SetProperty(KNownCameraAudioVideoProperties.VideoTorchMode,VideoTorchMode.On); // set flash power to maxinum avDevice.SetProperty(KNownCameraAudioVideoProperties.VideoTorchPower,AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation,KNownCameraAudioVideoProperties.VideoTorchPower).Max); } else { turnWhiteScreen(true); } } catch (Exception ex) { // Flashlight isn't supported on this device,instead show a White Screen as the flash light turnWhiteScreen(true); }
有任何想法吗?
附:
>我想象将.ons转换为.offs可能有效,但事实并非如此.
>这已经在HTC 8S和Lumia 820上进行了测试.
解决方法
看起来你无法检索两次采集设备(我不知道为什么),所以你应该将它存储在一个属性中:
protected AudioVideoCaptureDevice Device { get; set; } private async void ButtonTurnOn_Click(object sender,RoutedEventArgs e) { var sensorLocation = CameraSensorLocation.Back; try { if (this.Device == null) { // get the AudioViceoCaptureDevice this.Device = await AudioVideoCaptureDevice.OpenAsync(sensorLocation,AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First()); } // turn flashlight on var supportedCameraModes = AudioVideoCaptureDevice .GetSupportedPropertyValues(sensorLocation,KNownCameraAudioVideoProperties.VideoTorchMode); if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On)) { this.Device.SetProperty(KNownCameraAudioVideoProperties.VideoTorchMode,VideoTorchMode.On); // set flash power to maxinum this.Device.SetProperty(KNownCameraAudioVideoProperties.VideoTorchPower,KNownCameraAudioVideoProperties.VideoTorchPower).Max); } else { turnWhiteScreen(true); } } catch (Exception ex) { // Flashlight isn't supported on this device,instead show a White Screen as the flash light turnWhiteScreen(true); } }
然后,将其关闭:
private void ButtonTurnOff_Click(object sender,RoutedEventArgs e) { var sensorLocation = CameraSensorLocation.Back; try { // turn flashlight on var supportedCameraModes = AudioVideoCaptureDevice .GetSupportedPropertyValues(sensorLocation,KNownCameraAudioVideoProperties.VideoTorchMode); if (this.Device != null && supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.Off)) { this.Device.SetProperty(KNownCameraAudioVideoProperties.VideoTorchMode,VideoTorchMode.Off); } else { turnWhiteScreen(false); } } catch (Exception ex) { // Flashlight isn't supported on this device,instead show a White Screen as the flash light turnWhiteScreen(false); } }
原文地址:https://www.jb51.cc/csharp/243346.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。