[英]Windows Phone 8.1 camera initialization
我知道有更多重復的問題,但請,這對我來說非常重要。 我現在很難用Windows Phone 8.1 C#相機初始化。
async private void InitCamera_Click(object sender, RoutedEventArgs e)
{
captureManager = new MediaCapture();
await captureManager.InitializeAsync();
try
{
captureManager = new Windows.Media.Capture.MediaCapture();
await captureManager.InitializeAsync();
if (captureManager.MediaCaptureSettings.VideoDeviceId != "" && captureManager.MediaCaptureSettings.AudioDeviceId != "")
{
System.Diagnostics.Debug.WriteLine("Init successful");
captureManager.RecordLimitationExceeded += new Windows.Media.Capture.RecordLimitationExceededEventHandler(RecordLimitationExceeded);
captureManager.Failed += new Windows.Media.Capture.MediaCaptureFailedEventHandler(Failed);
}
else
{
System.Diagnostics.Debug.WriteLine("No Device");
}
}
catch (Exception exception)
{
System.Diagnostics.Debug.WriteLine("Exception raised!!!!:" + exception);
}
}
這是我初始化相機的代碼,但由於某種原因,它在Lumia 920上使用System.UnauthorizedAccessException
Windows.Media.Capture.MediaCapture()
構造函數調用失敗,並且在模擬器上也是訪問沖突。 我已經用Google搜索了這個問題,但到目前為止還沒有答案。 有些人告訴我不僅應該啟用網絡攝像頭,還要啟用麥克風,但這並沒有解決我的問題。 一切似乎設置得很好,所有訪問權限都在app清單中授予。 另外我想問你,如果你有一些很好的工作實例/教程用相機拍照,請提供。
下面是我的相機捕獲代碼,它有效,我在商店中提交了一個應用程序:
private MediaCapture mediaCapture = null;
private async Task StartCapture()
{
string error = null;
try
{
if (mediaCapture == null)
{
mediaCapture = new MediaCapture();
mediaCapture.Failed += mediaCapture_Failed;
var _deviceInformation = await GetCameraDeviceInfoAsync(Windows.Devices.Enumeration.Panel.Back);
var settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Video;
settings.PhotoCaptureSource = PhotoCaptureSource.VideoPreview;
settings.AudioDeviceId = "";
if (_deviceInformation != null)
settings.VideoDeviceId = _deviceInformation.Id;
await mediaCapture.InitializeAsync(settings);
var focusSettings = new FocusSettings();
focusSettings.AutoFocusRange = AutoFocusRange.FullRange;
focusSettings.Mode = FocusMode.Auto;
focusSettings.WaitForFocus = true;
focusSettings.DisableDriverFallback = false;
mediaCapture.VideoDeviceController.FocusControl.Configure(focusSettings);
await mediaCapture.VideoDeviceController.ExposureControl.SetAutoAsync(true);
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
}
captureReceipt.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
}
catch (Exception ex)
{
DisposeMediaCapture();
error = ex.Message;
}
if (error != null)
{
await (new MessageBoxImpl()).ShowMessageAsync(error);
}
}
private static async Task<DeviceInformation> GetCameraDeviceInfoAsync(Windows.Devices.Enumeration.Panel desiredPanel)
{
DeviceInformation device = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
.FirstOrDefault(d => d.EnclosureLocation != null && d.EnclosureLocation.Panel == desiredPanel);
if (device == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No suitable devices found for the camera of type {0}.", desiredPanel));
}
return device;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.