windows rt 扫描二维码

本文介绍了一个使用ZXing.net库在应用商店程序中捕获图片并解析二维码的过程,通过MediaCapture获取图片,转换为WriteableBitmap,使用ZXing进行解析以获取二维码的类型和文本值。

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

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

代码如下:

 1         private async void CaptureBarcode()
 2         {
 3             mediaCapture = new MediaCapture();
 4             await mediaCapture.InitializeAsync();
 5             captureElement.Source = mediaCapture;
 6             await mediaCapture.StartPreviewAsync();
 7             Result result = default(Result);
 8             while (true)
 9             {
10                 IRandomAccessStream stream = new InMemoryRandomAccessStream();
11                 await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreatePng(), stream);
12                 await stream.FlushAsync();
13                 stream.Seek(0);
14                 IBarcodeReader reader = new BarcodeReader();
15                 WriteableBitmap bitmap = new WriteableBitmap(640, 480);
16                 bitmap.SetSource(stream);
17                 if (bitmap == null)
18                     continue;
19                 result = reader.Decode(bitmap);
20                 if (result != null)
21                     break;
22                 continue;
23             }
24             if (result == default(Result))
25                 return;
26             await mediaCapture.StopPreviewAsync();
27             jsonFunc("{ \"type\":\"" + result.BarcodeFormat + "\",\"code\":\"" + result.Text + "\"}");
28         }

 

转载于:https://www.cnblogs.com/grj1046/p/3193901.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值