[Windows Phone] 在 Windows Phone 8 控制闪光灯

原文:[Windows Phone] 在 Windows Phone 8 控制闪光灯

?

前言

在 Windows Phone 如果想要控制闪光灯,该怎麽做?在 Windows Phone 8 提供类别与方法可直接控制闪光灯。

?

实作

AudioVideoCaptureDevice 类别用来撷取音乐和影片。

http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207322%28v=vs.105%29.aspx

?

首先宣告一个 AudioVideoCaptureDevice 类别变数 Device。

protected AudioVideoCaptureDevice Device { get; set; }

?

开启闪光灯

?

private async void ButtonTurnOnFlashLight_Click(object sender, RoutedEventArgs e)
{
    var sensorLocation = CameraSensorLocation.Back;

    try
    {
        if (this.Device == null)
        {
            //  取得 AudioViceoCaptureDevice
            this.Device = await AudioVideoCaptureDevice.OpenAsync(sensorLocation, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First());
        }

        // Turn on FlashLight
        var supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);
        if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
        {
            this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);

            // 设定亮度为最大
            this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
        }
    }
    catch (Exception ex)
    {
        // 无法控制闪光灯
    }
}

?

关闭闪光灯

?

private void ButtonTurnOnFlashLight_Click(object sender, RoutedEventArgs e)
{
    var sensorLocation = CameraSensorLocation.Back;

    try
    {
        var supportedCameraModes = AudioVideoCaptureDevice
            .GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);
        // Turn off FlashLight
        if (this.Device != null && supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.Off))
        {            this.Device.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
        }
    }
    catch (Exception ex)
    {
        // 无法控制闪光灯
    }
}

?


[Windows Phone] 在 Windows Phone 8 控制闪光灯

posted on 2013/10/2 02:40 | 我要推荐 | 阅读数 : 1214 | 订阅

上一篇:[Windows Phone] 地图控制项的经纬度


下一篇:一文读懂ML中的解析解与数值解