我使用Xamarin表单编写iOS应用程序并使用ZXing库扫描条形码。我正在尝试阅读驱动程序许可证(PDF417)条形码,但该库无法识别该条形码。
如果我在PossibleFormats中包含UPC或其他条形码,则会正确扫描它们。
我也确定我想读的条形码是PDF417条形码,因为当只使用PDF417条形码时,Scandit能够正确识别它。
这是我正在使用的代码。 我需要更改哪些内容才能正确识别PDF417条形码?
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);
}
答案 0 :(得分:4)
我几天前遇到了同样的问题并用以下内容修复了它。在MobileBarcodeScanningOptions
课程中,CameraResolutionSelectorDelegate
类型的属性称为CameraResolutionSelector
。您可以将其设置为从可用分辨率列表中返回更高的相机分辨率。所以MobileBarcodeScanningOptions
的实例化看起来像这样:
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)条形码。
Here's来自ZXing github的MobileBarcodeScanningOptions.cs
源代码。