【发布时间】:2015-03-25 23:48:23
【问题描述】:
我正在使用 ZXing.net 创建一个用户控件,用于使用相机将条形码扫描到 Windows Phone 8.1 RT 应用程序中。
条形码解码得很好,但是当调用 CapturePhotoToStreamAsync 方法时,我在 UI 上冻结了,即使它正在等待。 执行大约需要 600 毫秒。
我正在模拟器中测试应用程序。
以下代码以异步方法执行:
// Preview of the camera
await _mediaCapture.InitializeAsync(settings);
VideoCapture.Source = _mediaCapture;
VideoCapture.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight;
await _mediaCapture.StartPreviewAsync();
VideoEncodingProperties res = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
ImageEncodingProperties iep = ImageEncodingProperties.CreateBmp();
iep.Height = res.Height;
iep.Width = res.Width;
var barcodeReader = new BarcodeReader
{
TryHarder = true,
AutoRotate = true
};
WriteableBitmap wB = new WriteableBitmap((int)res.Width, (int)res.Height);
while (_result == null)
{
using (var stream = new InMemoryRandomAccessStream())
{
await _mediaCapture.CapturePhotoToStreamAsync(iep, stream);
stream.Seek(0);
await wB.SetSourceAsync(stream);
_result = barcodeReader.Decode(wB);
}
}
await _mediaCapture.StopPreviewAsync();
//callback to handle result
ScanCallback(_result.Text);
如何防止 UI 冻结?
【问题讨论】:
标签: c# windows-runtime windows-phone-8.1 zxing