如何使用ZXing.net.mobile库为Xamarin.Android读取2D条形码PDF-417

时间:2018-03-24 22:50:09

标签: c# xamarin.android zxing.net

我正在使用Xamarin.Android和ZXing.net.mobile C#库开发Android应用程序。

我想开发一款Android应用来扫描PDF-417中以base64字符串编码的二维条码。

这是我第一次使用这个库,但仍未找到有关如何使用该库的演示文档。

我已按照https://github.com/Redth/ZXing.Net.Mobilehere

中的示例进行操作

以下是我的活动代码:

using Android.App;
using Android.Widget;
using Android.OS;
using ZXing;
using ZXing.Mobile;
using System;
using System.Collections.Generic;

namespace BarcodeScannerDemo
{
    [Activity(Label = "ID Scanner Demo", MainLauncher = true)]
    public class MainActivity : Activity
    {
        Button buttonScan;

        MobileBarcodeScanner scanner;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            MobileBarcodeScanner.Initialize(Application);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            scanner = new MobileBarcodeScanner();

            buttonScan = FindViewById<Button>(Resource.Id.buttonScan);

            buttonScan.Click += ButtonScan_Click;
        }



        private async void ButtonScan_Click(object sender, EventArgs e)
        {
            var scannerOptions = new MobileBarcodeScanningOptions
            {
                PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.PDF_417 },
                TryHarder = true
            };

            var overlay = LayoutInflater.Inflate(Resource.Layout.CustomOverlay, null);

            Button buttonFlash = overlay.FindViewById<Button>(Resource.Id.buttonFlash);
            Button buttonCancel = overlay.FindViewById<Button>(Resource.Id.buttonCancel);

            buttonCancel.Click += (btnCancelSender, btnCancelEventArgs) => scanner.Cancel();
            buttonFlash.Click += (btnFlashSender, btnFlashEventArgs) => scanner.ToggleTorch();

            scanner.UseCustomOverlay = true;
            scanner.CustomOverlay = overlay;

            scanner.AutoFocus();

            HandleResult(await scanner.Scan(this, scannerOptions));
        }

        private void HandleResult(ZXing.Result result)
        {
            var message = "No Barcode!";

            if (result != null)
            {
                message = $"{result.BarcodeFormat}";
            }

            Toast.MakeText(this, message, ToastLength.Long).Show();
        }
    }
}

应用程序在设备上编译和安装,我没有收到运行时错误,但是我没有得到扫描结果。扫描仪只是继续重新聚焦。我已将条形码格式限制为PDF-417。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

得到bonetoadresponse

的答案