我在Win Phone 8上做了一个手电筒应用程序,但是我不能关掉LED,我怎么做?

我在Win Phone 8上做了一个手电筒应用程序,但是我不能关掉LED,我怎么做?,第1张

概述我在Win Phone 8上做了一个手电筒应用程序,但是我不能关掉LED,我怎么做?

我已经读了另一篇文章,使一个火炬的应用程序为诺基亚Lumia 820,我成功地打开领导,但是当我尝试closures它…我不能,我使用此代码,以打开它。

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 { //ShowWhiteScreenInsteadOfCameraTorch(); } } catch (Exception ex) { // Flashlight isn't supported on this device,instead show a White Screen as the flash light // ShowWhiteScreenInsteadOfCameraTorch(); }

你能帮我把闪光灯关掉吗? 谢谢。

我怎样才能让光盘在DVD ROM驱动器中旋转?

C#/ .net:报告subprocess状态到父服务

在ASP.NET中下载文件(通过服务器),同时将其传输给用户

在WinForms中如何处理隐形控件?

为什么threadpool.QueueUserWorkItem创build这么多事件句柄?

.Net的窗口菜单

与Multi-touch Manipulations相关的未公开的.NET代码引发exception

我可以限制进程的RAM使用情况吗?

元素不存在或虚拟化; 如果支持,使用VirtualizedItem模式

保存到Excel文件导致在C#窗口中的错误

这里有一个完整的解决方案,我刚刚完成了一个适用于windows Phone 8的振动摇杆/闪光灯。请记住在WMAppManifest.xml中设置摄像头和麦克风设备大小。 摇动打开/关闭。 它使用ShakeGestures库来捕捉抖动。

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; } } }

而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,28"> <TextBlock x:name="_TitleTextBlock" Text="MY APPliCATION" {StaticResource PhoneTextnormalStyle}" margin="12,0"/> <TextBlock x:name="_pagenameTextBlock" Text="page name" margin="9,-7,0" {StaticResource PhoneTextTitle1Style}"/> </StackPanel> <!--ContentPanel - place additional content here--> <GrID x:name="_contentGrID" GrID.Row="1" margin="12,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" GrID.Row="0" GrID.rowspan="2" IsHitTestVisible="False" />--> </GrID> </phone:PhoneApplicationPage>

总结

以上是内存溢出为你收集整理的我在Win Phone 8上做了一个手电筒应用程序,但是我不能关掉LED,我怎么做?全部内容,希望文章能够帮你解决我在Win Phone 8上做了一个手电筒应用程序,但是我不能关掉LED,我怎么做?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1281268.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存