我正在将Visual Studio 2017与Xamarin和ZXing.Net.Mobile 2.4.1的最新软件包一起使用。我安装了标准的条形码读取器,如果我从显示器的VIN条形码图像中扫描VIN编号,它似乎可以工作,但是如果我在真正的汽车上尝试使用它,则大约需要进行三次尝试才能将其显示在我要在其中显示结果的Edittext。我更改了代码以将结果放入Toast中,并且每次尝试都可以使用,但是一旦更改以将结果放入Edittext中,它似乎就需要进行多次尝试。
谁能告诉我我可能做错了什么?
这是我正在使用的代码:
//Barcode scanner
Button buttonScanCustomView = this.FindViewById<Button>(Resource.Id.buttonScanCustomView);
buttonScanCustomView.Click += async delegate
{
MobileBarcodeScanner.Initialize(Application);
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
scanner.AutoFocus();
scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away";
scanner.BottomText = "Wait for the barcode to automatically scan!";
var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
options.UseCode39ExtendedMode = true;
options.TryHarder = true;
options.AutoRotate = false;
options.PossibleFormats = new System.Collections.Generic.List<ZXing.BarcodeFormat>()
{
ZXing.BarcodeFormat.CODE_39
};
var result = await scanner.Scan(new MobileBarcodeScanningOptions { AutoRotate = false });
if (result != null)
{
HandleScanResult(result, VIN);
}
else
{
Android.Widget.Toast.MakeText(this, "Barcode not found. Please re-scan.", Android.Widget.ToastLength.Short).Show();
}
};
void HandleScanResult(ZXing.Result result, EditText txtVIN)
{
string msg = "";
if (result != null && !string.IsNullOrEmpty(result.Text))
msg = GetCleanVIN(result.Text);
else
msg = "Scanning Canceled!";
//this.RunOnUiThread(() => Toast.MakeText(this, msg, ToastLength.Short).Show());
this.RunOnUiThread(() => txtVIN.Text = msg);
}