Windows Phone 8.1 MediaCapture的FocusAsync不起作用

时间:2015-12-02 15:40:28

标签: c# camera windows-phone-8.1 focus

我正在使用QR码阅读器实现Windows Phone 8.1应用程序。我使用ZXing.NET来分析拍摄的图像并尝试解析QR。为了提高效率,我还为相机设置了自动对焦功能。它在第一次启动时运行良好,但不是第二次尝试(f.e. after suspend - resume或restart capture)。在我测试时,FocusAsync方法有时不返回并阻止所有内容。

这里发生了什么?可能是什么问题?

这是我目前的代码。

焦点

var focusSettings = new Windows.Media.Devices.FocusSettings();
focusSettings.AutoFocusRange = Windows.Media.Devices.AutoFocusRange.Normal;
focusSettings.Mode = Windows.Media.Devices.FocusMode.Auto;

CaptureManager.VideoDeviceController.FocusControl.Configure(focusSettings);

MainProcess

... Initialization ...  

ImageEncodingProperties imaggeProperties = ImageEncodingProperties.CreateJpeg();
imaggeProperties.Width = ViewModel.ImageWidth;
imaggeProperties.Height = ViewModel.ImageHeight;

InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream();

LoggingAdapter.Instance.WriteDebugLog("Scanning is in progress. " + Environment.CurrentManagedThreadId);       
await CaptureManager.VideoDeviceController.FocusControl.FocusAsync();
await CaptureManager.CapturePhotoToStreamAsync(imaggeProperties, memoryStream);
LoggingAdapter.Instance.WriteDebugLog("Photo captured.");

var bcReader = new BarcodeReader();

... Processing the barcode ...

清洗

if (CaptureManager != null)
{
   if (InProgress)
   {
     InProgress = false;
     await CaptureManager.StopPreviewAsync();
   }
   CaptureManager.Dispose();
   Capture.Source = null;
  }

感谢您提前!

1 个答案:

答案 0 :(得分:0)

我成功实施了一个有效的解决方案。我在FocusSettings中将WaitForFocus设置为false,它似乎工作正常,也可以暂停或取消。