我正在尝试制作一个简单的网络摄像头应用程序:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Media.MediaProperties;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
namespace App1
{
public sealed partial class MainPage : Page
{
private Windows.Media.Capture.MediaCapture m_mediaCaptureMgr;
private Windows.Storage.StorageFile m_photoStorageFile;
private readonly String PHOTO_FILE_NAME = "photo.jpg";
public MainPage()
{
this.InitializeComponent();
}
internal async void initializeCamera()
{
m_mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
await m_mediaCaptureMgr.InitializeAsync();
statusBox.Text = "initialized";
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
internal async void takePicture(object sender, RoutedEventArgs e)
{
m_photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
await m_mediaCaptureMgr.CapturePhotoToStorageFileAsync(imageProperties, m_photoStorageFile);
}
private void initializeButton(object sender, RoutedEventArgs e)
{
initializeCamera();
}
}
}
然而,当我点击initializeButton时,我得到了一个例外:
UnauthorizedAccessException (Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)))
这可能是什么问题?
编辑:我发现了这个错误。基本上,如果网络摄像头已经初始化,尝试再次初始化它将触发异常。所以我不得不放一个标志,一些尝试/捕捉
答案 0 :(得分:1)
您是否在清单文件中设置了麦克风和网络摄像头的功能?
答案 1 :(得分:0)
在Package.Appmnifest
文件