如何在 iOS 10.2 上使用 xamarin forms + zxing 扫描驾照 (PDF417) [英] How to scan driver's license (PDF417) using xamarin forms + zxing on iOS 10.2
问题描述
我正在使用 Xamarin 表单编写 iOS 应用程序并使用 ZXing 库扫描条形码.我正在尝试读取驾驶执照 (PDF417) 条形码,但图书馆无法识别该条形码.
I am using Xamarin forms to write an iOS app and using the ZXing library to scan barcodes. I am trying to read a driver's license (PDF417) barcode, but the library is not able to recognize that barcode.
如果我在可能的格式中包含 UPC 或其他条形码,它们将被正确扫描.
If I include UPC or other barcodes in the PossibleFormats, they are scanned correctly.
我也确定我尝试读取的条码是 PDF417 条码,因为 Scandit 能够在仅使用 PDF417 条码时正确识别它.
I am also certain the barcode I am trying to read is PDF417 barcode because Scandit is able to recognize it correctly while using only PDF417 barcode.
这是我正在使用的代码.我需要更改什么才能正确识别 PDF417 条码?
Here is the code I am using. What do I need to change so that the PDF417 barcode is recognized correctly?
async void Handle_Clicked (object sender, System.EventArgs e)
{
MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions ();
options.PossibleFormats = new List<ZXing.BarcodeFormat> () {
ZXing.BarcodeFormat.PDF_417
};
options.TryHarder = true;
var scanPage = new ZXingScannerPage (options);
scanPage.OnScanResult += (result) => {
// Stop scanning
scanPage.IsScanning = false;
// Pop the page and show the result
Device.BeginInvokeOnMainThread (async () => {
await Navigation.PopAsync ();
await DisplayAlert ("Scanned Barcode", result.Text, "OK");
});
};
// Navigate to our scanner page
await Navigation.PushAsync (scanPage);
}
推荐答案
几天前我遇到了这个完全相同的问题,并使用以下方法修复了它.在 MobileBarcodeScanningOptions
类中有一个 CameraResolutionSelectorDelegate
类型的属性,称为 CameraResolutionSelector
.您可以将其设置为从可用分辨率列表中返回更高的相机分辨率.所以我的 MobileBarcodeScanningOptions
实例化看起来像这样:
I ran into this exact same issue a few days ago and fixed it with the following. In the MobileBarcodeScanningOptions
class there's a property of type CameraResolutionSelectorDelegate
called CameraResolutionSelector
. You can set this to return a higher camera resolution from a list of available resolutions. So my instantiation of MobileBarcodeScanningOptions
looks like this:
var options = new MobileBarcodeScanningOptions {
TryHarder = true,
CameraResolutionSelector = HandleCameraResolutionSelectorDelegate,
PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.PDF_417 }
};
还有我的HandleCameraResolutionSelectorDelegate
:
CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
{
//Don't know if this will ever be null or empty
if (availableResolutions == null || availableResolutions.Count < 1)
return new CameraResolution () { Width = 800, Height = 600 };
//Debugging revealed that the last element in the list
//expresses the highest resolution. This could probably be more thorough.
return availableResolutions [availableResolutions.Count - 1];
}
这就是我要扫描驾驶执照 (PDF417) 条码所需的全部更改.
That's all I needed to change to get a driver's license (PDF417) barcode to scan.
这里是 MobileBarcodeScanningOptions.cs
的源代码来自 ZXing github.
Here's the source code for MobileBarcodeScanningOptions.cs
from ZXing github.
这篇关于如何在 iOS 10.2 上使用 xamarin forms + zxing 扫描驾照 (PDF417)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!