• windows rt 扫描二维码


    项目中使用的是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         }
  • 相关阅读:
    如何一次性杀掉几千个的linux进程
    获取字符串中全部的回文子串
    python 中常用的高阶函数
    (python)字符串中找出连续最长的数字串
    批量更新 mytais
    Java Stream
    内存区域
    lock上
    Java代理
    heap、stack
  • 原文地址:https://www.cnblogs.com/grj1046/p/3193901.html
Copyright © 2020-2023  润新知