Control Widows Media Device Flash Light

时间:2015-10-06 08:27:22

标签: c# windows-8.1 windows-applications

I am trying to create a simple application which will have the functionality to switch on and off the flash light in a Windows Media Device. I have initialized the camera as following:

    var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

    var rearCamera = devices.FirstOrDefault(item => item.EnclosureLocation != null &&
                                                item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
    if (rearCamera != null)
    {
        DeviceName.Content = rearCamera.Name;
        FlashButton.Visibility = System.Windows.Visibility.Visible;
        mediaCapture = new MediaCapture();

        await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
        {
            VideoDeviceId = rearCamera.Id
        });

        LowLagPhotoCapture lowLagCaptureMgr = null;
        // Image properties
        ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();

        // Create LowLagPhotoCapture object
        lowLagCaptureMgr = await mediaCapture.PrepareLowLagPhotoCaptureAsync(imgFormat);

    }

And to switch on the flash I have written the following code:

        var MyVideoDeviceController = mediaCapture.VideoDeviceController;



        var MyTorch = MyVideoDeviceController.TorchControl;
        var MyFlash = MyVideoDeviceController.FlashControl;

        if (MyTorch.Supported)
        {
            MyTorch.PowerPercent = 100;
            MyTorch.Enabled = true;
        }
        else
        {
            if (MyFlash.Supported)
            {
                MyFlash.PowerPercent = 100;
                MyFlash.Enabled = true;
            }
            else
            {
                MessageBox.Show("No Flash and Torch Support", "Flash and Torch");
            }
        }

But seems both TorchControl and FlashControl are not supported in the code. I am not sure if am using the right APIs too. I am trying to run this on a Motion F5m - Tablet PC

Thanks in advance

1 个答案:

答案 0 :(得分:3)

TorchControl用于常量视频灯,因此如果您正在拍摄照片,则它不是最适合使用的控件。一个原因是,在许多设备上,视频灯将比照片闪光灯更暗,但特别是因为在某些设备上,手电筒只会在视频录制过程中打开。根据设备的功能,这可能会影响拍照的能力。

你有正确的想法设置MyFlash.Enabled = true,但为了安全起见,我还会设置MyFlash.Auto = false,这样闪光灯每次都会闪光,而不仅仅是在天黑时。

Microsoft GitHub存储库中的CameraManualControls示例向您展示了如何使用Flash和Torch控件等等。它的目标是Windows 10,所以如果你使用的是8.1,那么你必须调整代码或升级你的平板电脑。

现在,以上所有内容都假设您运行应用程序的设备首先具有闪存支持。当您说控件不受支持时,这意味着设备上的摄像头驱动程序没有向Windows宣传该功能。我假设内置的Microsoft Camera应用程序不允许你使用闪存?

我看到平板电脑的制造商在camera specs list上列出了“照明灯”,但控制它的唯一方法是通过其专有应用程序。在这种情况下,你必须联系他们寻求支持。