windows rt 扫描二维码

项目中使用的是ZXing.net,应用商店程序。使用到的dll是ZXing.winmd。

大致思路为,使用MediaCapture捕获图片。获取到CapturePhotoToStreamAsync流,然后将其转换为WriteableBitmap,使用ZXing进行解析,该项目主要是为了获取二维码类型和文本值。

代码如下:

         private async void CaptureBarcode()
{
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
captureElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
Result result = default(Result);
while (true)
{
IRandomAccessStream stream = new InMemoryRandomAccessStream();
await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreatePng(), stream);
await stream.FlushAsync();
stream.Seek();
IBarcodeReader reader = new BarcodeReader();
WriteableBitmap bitmap = new WriteableBitmap(, );
bitmap.SetSource(stream);
if (bitmap == null)
continue;
result = reader.Decode(bitmap);
if (result != null)
break;
continue;
}
if (result == default(Result))
return;
await mediaCapture.StopPreviewAsync();
jsonFunc("{ \"type\":\"" + result.BarcodeFormat + "\",\"code\":\"" + result.Text + "\"}");
}
上一篇:php读取图片成二进制流输出


下一篇:Ireport5.0.1 从java后台接收list集合