简体   繁体   English

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

[英]How to scan driver's license (PDF417) using xamarin forms + zxing on iOS 10.2

I am using Xamarin forms to write an iOS app and using the ZXing library to scan barcodes. 我正在使用Xamarin表单编写iOS应用程序,并使用ZXing库扫描条形码。 I am trying to read a driver's license (PDF417) barcode, but the library is not able to recognize that barcode. 我正在尝试读取驾驶执照(PDF417)条码,但该库无法识别该条码。

If I include UPC or other barcodes in the PossibleFormats, they are scanned correctly. 如果我在“可能的格式”中包含UPC或其他条形码,则它们将被正确扫描。

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条形码,因为Scandit能够仅使用PDF417条形码就能正确识别它。

Here is the code I am using. 这是我正在使用的代码。 What do I need to change so that the PDF417 barcode is recognized correctly? 我需要更改什么才能正确识别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);
    }

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 . MobileBarcodeScanningOptions类中,有一个类型为CameraResolutionSelectorDelegate的属性,称为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: 因此,我对MobileBarcodeScanningOptions实例如下所示:

var options = new MobileBarcodeScanningOptions {
            TryHarder = true,
            CameraResolutionSelector = HandleCameraResolutionSelectorDelegate,
            PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.PDF_417 }
        };

And my HandleCameraResolutionSelectorDelegate : 和我的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];
}

That's all I needed to change to get a driver's license (PDF417) barcode to scan. 这就是我需要更改以获取要扫描的驾照(PDF417)条码的全部内容。

Here's the source code for MobileBarcodeScanningOptions.cs from ZXing github. 这是来自ZXing github的MobileBarcodeScanningOptions.cs的源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM