如何在iOS 10.2上使用Xamarin Forms + Zxing扫描驾照(PDF417)

xde*_*dev 3 c# barcode xamarin.ios zxing xamarin

我使用Xamarin的形式来写的iOS应用,并使用斑马线库扫描条形码。我想读驾照(PDF417)条形码,但库是不能够识别条形码。

如果我有UPC或其他条形码在PossibleFormats,他们正在正确扫描。

我也确定我要读取的条形码是PDF417条形码,因为Scandit能够仅使用PDF417条形码就能正确识别它。

这里是我使用的代码。我需要做什么改变,这样的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);
    }
Run Code Online (Sandbox Code Playgroud)

小智 6

几天前,我遇到了这个完全相同的问题,并通过以下内容进行了修复。在MobileBarcodeScanningOptions该类中,有一个CameraResolutionSelectorDelegate名为的类型的属性CameraResolutionSelector。您可以将其设置为从可用分辨率列表中返回更高的相机分辨率。因此,我的实例化MobileBarcodeScanningOptions如下所示:

var options = new MobileBarcodeScanningOptions {
            TryHarder = true,
            CameraResolutionSelector = HandleCameraResolutionSelectorDelegate,
            PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.PDF_417 }
        };
Run Code Online (Sandbox Code Playgroud)

而我的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];
}
Run Code Online (Sandbox Code Playgroud)

这就是我需要更改以获取要扫描的驾照(PDF417)条码的全部内容。

这是MobileBarcodeScanningOptions.cs ZXing github 的源代码。