c# – Windows Phone 8.1摄像头初始化
发布时间:2020-12-16 02:03:17 所属栏目:百科 来源:网络整理
导读:我知道有更多重复的问题,但请,这对我来说非常重要.我现在很难用 Windows Phone 8.1 C#相机初始化. async private void InitCamera_Click(object sender,RoutedEventArgs e) { captureManager = new MediaCapture(); await captureManager.InitializeAsync();
我知道有更多重复的问题,但请,这对我来说非常重要.我现在很难用
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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |