[英]How do I read 2D barcode PDF-417 using ZXing.net.mobile library for Xamarin.Android
I am developing an Android app using Xamarin.Android and the ZXing.net.mobile C# library. 我正在使用Xamarin.Android和ZXing.net.mobile C#库开发一个Android应用程序。
I want to develop an Android app to scan 2D barcode in PDF-417 that is encoded in base64 string. 我想开发一个Android应用程序来扫描以base64字符串编码的PDF-417中的二维条形码。
This is my first time to use this library and still have not found documentation for a walk-through on how to use the library. 这是我第一次使用此库,但仍未找到有关如何使用该库的演练文档。
I have followed the example here https://github.com/Redth/ZXing.Net.Mobile and here 我在https://github.com/Redth/ZXing.Net.Mobile和此处都遵循了示例
Below is my activity code: 以下是我的活动代码:
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();
}
}
}
Application compiles and installs on device, I don't get a runtime error but I don't get the scan result. 应用程序编译并安装在设备上,我没有得到运行时错误,但没有得到扫描结果。 Scanner just keeps on refocusing.
扫描仪只是一直在重新对焦。 I have restricted the barcode format to PDF-417.
我已将条形码格式限制为PDF-417。
What am I doing wrong? 我究竟做错了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.