###前提・実現したいこと
WindowsPhoneのカメラを自作アプリで使えるようにしたい。
C++でプログラミングをしていたのですが、サンプルコード等が見当たらない為C#で作成し、それを流用しようと考えています。
###発生している問題・エラーメッセージ
発生している問題
PC内でのデバッグではCaptureElementが動作するのですが、実機デバッグすると下記のようなエラーが出て何も表示されません。 ※現段階ではシャッターボタンを押しても写真を撮ることができません。
エラーメッセージ
型 'System.UnauthorizedAccessException' の初回例外が mscorlib.ni.dll で発生しました 追加情報:Access is denied.
###該当のソースコード
C#
public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; } /// <summary> /// このページがフレームに表示されるときに呼び出されます。 /// </summary> /// <param name="e">このページにどのように到達したかを説明するイベント データ。 /// このプロパティは、通常、ページを構成するために使用します。</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { //バックカメラを取得 var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); var backDevice = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back); if (backDevice == null) { backDevice = devices[0]; } //メディアキャプチャーをセットアップしCaptureElementと関連付ける var MediaCapture = new MediaCapture(); var settings = new MediaCaptureInitializationSettings {VideoDeviceId = backDevice.Id }; await MediaCapture.InitializeAsync(settings); this.CapE.Source = MediaCapture; await MediaCapture.StartPreviewAsync(); } protected override async void OnNavigatedFrom(NavigationEventArgs e) { //メディアキャプチャーの後始末 await this.CapE.Source.StopPreviewAsync(); this.CapE.Source.Dispose(); this.CapE.Source = null; } }
App.g.i.cs
(エラーが出た時★以降がピックアップされます) #if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION UnhandledException += (sender, e) => { if (global::System.Diagnostics.Debugger.IsAttached) ★global::System.Diagnostics.Debugger.Break(); }; #endif
Xaml
<Page x:Class="CStstCamera.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:CStstCamera" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid Background="Black" Margin="0"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <CaptureElement Grid.Row="0" Name="CapE" Stretch="UniformToFill"/> <StackPanel x:Name="StackP" Grid.Row="1" Background="Black"> <AppBarButton x:Name="ApBar" VerticalAlignment="Center" HorizontalAlignment="Center" Icon="Camera"/> </StackPanel> </Grid> </Page>
###試したこと
検索してみてヒットした「http://hiho-developer.hatenablog.com/entry/20140525/1400995398」を試してみましたがダメでした。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/12 04:32
2017/01/12 04:45
2017/01/12 04:54