我使用MediapCapture扫描QrCode。这是我的配置:
var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
int cameraIndex = cameras.Count > 1 ? 1 : 0;
MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameras[cameraIndex].Id };
settings.StreamingCaptureMode = StreamingCaptureMode.Video;
await _mediaCapture.InitializeAsync();
SetResolution();
_mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
_mediaCapture.VideoDeviceController.FocusControl.Configure(new Windows.Media.Devices.FocusSettings() { Mode = Windows.Media.Devices.FocusMode.Auto });
videoCapture.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();
我的CaptureElement上还有一个Tapped事件,它调用了FocusAsync方法:
await _mediaCapture.VideoDeviceController.FocusControl.FocusAsync();
我的问题是,当我尝试聚焦时,我有时(并非总是)会出现错误(即使它是我第一次调用它时)。此错误是:
操作无效
修改
这是我的堆栈跟踪:(没有内部异常)
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在System.Runtime.CompilerServices.TaskAwaiter.GetResult() 在ProjectName.Views.QrCodeScannerPage.d__8.MoveNext()
答案 0 :(得分:1)