的Windows Phone 8.1初始化摄像头

编程入门 行业动态 更新时间:2024-10-26 04:21:51
本文介绍了的Windows Phone 8.1初始化摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道大约有更多这方面的重复的问题,但请,这对我很重要超强。我有Windows Phone的8.1 ​​C#相机初始化现在日子不好过。

I am aware about that there are more duplicate questions about this, but please, it is super important to me. I have hard time now with Windows Phone 8.1 C# camera initialization.

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

这是我的代码初始化的摄像头,但对于一些原因它 Windows.Media.Capture.MediaCapture()构造与 System.UnauthorizedAccessException的呼叫失败上的Lumia 920也在仿真器访问冲突。我GOOGLE了对这个问题,但没有答案为止。有些人告诉我,我应该能够不只是摄像头,而且还话筒,但是这并没有解决我的问题。一切似乎得到很好的设置,所有的访问是在应用程序清单理所当然的。此外,我想问问你,如果你有拍照与摄像头有些是好的,工作的例子/教程,请提供。

this is my code to initialize camera, but for some reason it fails on Windows.Media.Capture.MediaCapture() constructor call with System.UnauthorizedAccessException on Lumia 920 and also Access Violation on emulator. I've googled about the issue, but no answers so far. Some folks told that I should enable not just webcam, but also microphone, but that did not solved my issue. Everything seems to be well set, all access were granted in app manifest. Also I want to ask you, if you have some good and working example/tutorial of taking pictures with camera, please provide.

推荐答案

下面是我的摄像头采集,其工作方式,我在商店提交应用程序的代码:

Below is my code for camera capture, which works, I have a submitted app in the store:

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

更多推荐

的Windows Phone 8.1初始化摄像头

本文发布于:2023-11-06 17:28:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564329.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   摄像头   Windows   Phone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!