簡體   English   中英

如何使用Xamarin.Android的ZXing.net.mobile庫讀取2D條碼PDF-417

[英]How do I read 2D barcode PDF-417 using ZXing.net.mobile library for Xamarin.Android

我正在使用Xamarin.Android和ZXing.net.mobile C#庫開發一個Android應用程序。

我想開發一個Android應用程序來掃描以base64字符串編碼的PDF-417中的二維條形碼。

這是我第一次使用此庫,但仍未找到有關如何使用該庫的演練文檔。

我在https://github.com/Redth/ZXing.Net.Mobile此處都遵循了示例

以下是我的活動代碼:

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。

我究竟做錯了什么?

得到了從骨頭蟾蜍答復

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM