【问题标题】:How do I read 2D barcode PDF-417 using ZXing.net.mobile library for Xamarin.Android如何使用 Xamarin.Android 的 ZXing.net.mobile 库读取二维条码 PDF-417
【发布时间】:2018-03-24 22:50:08
【问题描述】:

我正在使用 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。

我做错了什么?

【问题讨论】:

    标签: c# xamarin.android zxing.net


    【解决方案1】:

    得到了bonetoadresponse的答复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多