我正在使用xamarin.android和zxing.net.net.mobile c#library。
开发Android应用我想开发一个Android应用来扫描base64字符串中编码的PDF-417中的2D条形码。
这是我第一次使用此库,但仍未找到有关如何使用图书馆的段落的文档。
我在此处遵循了示例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。
我在做什么错?
从bonetoad的响应中得到答案