Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# I';我在Win Phone 8中制作了一个torch应用程序,但我无法关闭led,我该怎么做?_C#_.net_Windows_Windows Phone 8_Flashlight - Fatal编程技术网

C# I';我在Win Phone 8中制作了一个torch应用程序,但我无法关闭led,我该怎么做?

C# I';我在Win Phone 8中制作了一个torch应用程序,但我无法关闭led,我该怎么做?,c#,.net,windows,windows-phone-8,flashlight,C#,.net,Windows,Windows Phone 8,Flashlight,我在“其他”中读了另一篇文章,为mi Nokia Lumia 820制作torch应用程序,我成功地打开了led,但当我尝试关闭它时。。。我不能,我使用这个代码是为了打开它 var传感器位置=摄像机传感器位置。返回 try { // get the AudioViceoCaptureDevice var avDevice = await AudioVideoCaptureDevice.OpenAsync(sensor

我在“其他”中读了另一篇文章,为mi Nokia Lumia 820制作torch应用程序,我成功地打开了led,但当我尝试关闭它时。。。我不能,我使用这个代码是为了打开它

var传感器位置=摄像机传感器位置。返回

        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 
            {
                //ShowWhiteScreenInsteadOfCameraTorch();

            }

        }
        catch (Exception ex)
        {
            // Flashlight isn't supported on this device, instead show a White Screen as the flash light
           // ShowWhiteScreenInsteadOfCameraTorch();
        }
你能帮我把闪光灯关掉吗?
谢谢。

这是我刚刚完成的针对Windows Phone 8的摇壶手电筒/闪光灯的完整解决方案。请记住在WMAppManifest.xml中设置摄像头和麦克风设备封盖。摇动以打开/关闭。它使用ShakePictures库捕获震动

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using Microsoft.Phone.Controls;
using ShakeGestures;
using Windows.Phone.Media.Capture;

namespace ShakerTorch
{
    public partial class MainPage : PhoneApplicationPage
    {
        #region Initialisation

        private AudioVideoCaptureDevice _captureDevice;
        private bool _flashOn;
        private const CameraSensorLocation _sensorLocation = CameraSensorLocation.Back;

        public MainPage()
        {
            InitializeComponent();
            ShakeGesturesHelper.Instance.ShakeGesture += OnShake;
            ShakeGesturesHelper.Instance.MinimumRequiredMovesForShake = 5;
            ShakeGesturesHelper.Instance.Active = true;
            InitialiseCaptureDevice();
        }

        #endregion

        private async void InitialiseCaptureDevice()
        {
            _captureDevice = await GetCaptureDevice();
        }

        private void OnShake(object sender, ShakeGestureEventArgs e)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    switch (e.ShakeType)
                    {
                        case ShakeType.X:
                            {
                                _shakeStatusTextBlock.Text = string.Format("Left and right ({0})", e.ShakeType);
                                _shakeStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                                break;
                            }
                        case ShakeType.Y:
                            {
                                _shakeStatusTextBlock.Text = string.Format("Forward and backwards ({0})", e.ShakeType);
                                _shakeStatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                                break;
                            }
                        case ShakeType.Z:
                            {
                                _shakeStatusTextBlock.Text = string.Format("Up and down ({0})", e.ShakeType);
                                _shakeStatusTextBlock.Foreground = new SolidColorBrush(Colors.Blue);
                                break;
                            }
                    }
                    ToggleFlash();
                });
        }

        private void ToggleFlash()
        {
            try
            {
                IReadOnlyList<object> supportedCameraModes =
                    AudioVideoCaptureDevice.GetSupportedPropertyValues(_sensorLocation,
                                                                       KnownCameraAudioVideoProperties.VideoTorchMode);
//ToDo Don't like this line. Simplify....
                if (supportedCameraModes.ToList().Contains((UInt32) VideoTorchMode.On))
                {
                    if (!_flashOn)
                    {
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
                                                   AudioVideoCaptureDevice.GetSupportedPropertyRange(_sensorLocation,
                                                                                                     KnownCameraAudioVideoProperties
                                                                                                         .VideoTorchPower)
                                                                          .Max);
                        _contentGrid.Background = new SolidColorBrush(Colors.White);
                        _flashOn = true;
                    }
                    else
                    {
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
                        _contentGrid.Background = null;
                        _flashOn = false;
                    }
                }
            }
            catch (Exception ex)
            {
                _shakeStatusTextBlock.Text = "The flash cannot be controlled on this device.";
            }
        }

        private async Task<AudioVideoCaptureDevice> GetCaptureDevice()
        {
            AudioVideoCaptureDevice captureDevice =
                await
                AudioVideoCaptureDevice.OpenAsync(_sensorLocation,
                                                  AudioVideoCaptureDevice.GetAvailableCaptureResolutions(_sensorLocation)
                                                                         .First());
            return captureDevice;
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Media;
使用Microsoft.Phone.Controls;
使用手势;
使用Windows.Phone.Media.Capture;
名称空间ShakerTorch
{
公共部分类主页:PhoneApplicationPage
{
#区域初始化
专用音频视频捕获设备\u捕获设备;
私人布卢闪光;
private const CameraSensorLocation _sensorLocation=CameraSensorLocation.Back;
公共主页()
{
初始化组件();
ShakeGesturesHelper.Instance.ShakeSignature+=OnShake;
ShakeGesturesHelper.Instance.MinimumRequiredMovesForShake=5;
ShakeGesturesHelper.Instance.Active=true;
InitialiseCaptureDevice();
}
#端区
私有异步void InitialiseCaptureDevice()
{
_captureDevice=等待GetCaptureDevice();
}
私有void OnShake(对象发送方,ShakeGestureEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(()=>
{
开关(e.振动式)
{
case ShakeType.X:
{
_shakeStatusTextBlock.Text=string.Format(“左和右({0})”,e.ShakeType;
_shakeStatusTextBlock.前台=新的SolidColorBrush(Colors.Red);
打破
}
案例类型Y:
{
_shakeStatusTextBlock.Text=string.Format(“向前和向后({0})”,e.ShakeType);
_shakeStatusTextBlock.前台=新的SolidColorBrush(Colors.Green);
打破
}
case ShakeType.Z:
{
_shakeStatusTextBlock.Text=string.Format(“向上和向下({0})”,e.ShakeType);
_shakeStatusTextBlock.前台=新的SolidColorBrush(Colors.Blue);
打破
}
}
切换flash();
});
}
私有void ToggleFlash()
{
尝试
{
IReadOnlyList支持的CameraModes=
AudioVideoCaptureDevice.GetSupportedPropertyValue(\u sensorLocation,
了解MeraAudiovideProperties.VideoTorchMode);
//托多不喜欢这一行。简化。。。。
if(supportedCameraModes.ToList()包含((UInt32)VideoTorchMode.On))
{
如果(!\u闪光灯)
{
_SetProperty(知道ncameraaaudiovideoproperties.VideoTorchMode,VideoTorchMode.On);
_captureDevice.SetProperty(知道ncameraaaudiovideoProperties.VideoTorchPower,
AudioVideoCaptureDevice.GetSupportedPropertyRange(\u传感器位置,
KnownCameraAudioVideoProperties
.VideoTorchPower)
(最大值);
_contentGrid.Background=新的SolidColorBrush(Colors.White);
_闪光=真;
}
其他的
{
_captureDevice.SetProperty(knownCameraaaudiovideoproperties.VideoTorchMode,VideoTorchMode.Off);
_contentGrid.Background=null;
_闪光=假;
}
}
}
捕获(例外情况除外)
{
_shakeStatusTextBlock.Text=“无法在此设备上控制闪存。”;
}
}
专用异步任务GetCaptureDevice()
{
音频视频捕获设备捕获设备=
等待
AudioVideoCaptureDevice.OpenAsync(\u sensorLocation,
AudioVideoCaptureDevice.GetAvailableCaptureResolutions(传感器位置)
.First());
返回捕获装置;
}
}
}
还有Xaml

<phone:PhoneApplicationPage
    x:Class="ShakerTorch.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="_layoutRootGrid" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- LOCALIZATION NOTE:
            To localize the displayed strings copy their values to appropriately named
            keys in the app's neutral language resource file (AppResources.resx) then
            replace the hard-coded text value between the attributes' quotation marks
            with the binding clause whose path points to that string name.

            For example:

                Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"

            This binding points to the template's string resource named "ApplicationTitle".

            Adding supported languages in the Project Properties tab will create a
            new resx file per language that can carry the translated values of your
            UI strings. The binding in these examples will cause the value of the
            attributes to be drawn from the .resx file that matches the
            CurrentUICulture of the app at run time.
         -->

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="_titleStackPanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="_titleTextBlock" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
            <TextBlock x:Name="_pageNameTextBlock" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="_contentGrid" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock x:Name="_shakeStatusTextBlock" Text="Shake me..." FontSize="36" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </Grid>

        <!--Uncomment to see an alignment grid to help ensure your controls are
            aligned on common boundaries.  The image has a top margin of -32px to
            account for the System Tray. Set this to 0 (or remove the margin altogether)
            if the System Tray is hidden.

            Before shipping remove this XAML and the image itself.-->
        <!--<Image Source="/Assets/AlignmentGrid.png" VerticalAlignment="Top" Height="800" Width="480" Margin="0,-32,0,0" Grid.Row="0" Grid.RowSpan="2" IsHitTestVisible="False" />-->
    </Grid>

</phone:PhoneApplicationPage>


您只是限制了那些能够回答Lumia问题并愿意建立测试项目来帮助您的人。如果你能解释一下关掉它的实际问题,那会很有帮助的。嗨,SurfRat和Eduardo Tenorio Mayo,谢谢你分享火炬灯代码。我有一个问题,这个代码是否适用于所有WP8设备(诺基亚、HTC、三星)?以上代码是否有支持所有va的GOTCHA