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

空扰寡人 提交于 2019-12-01 01:27:06

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 }
        };

And my 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.

Here's the source code for MobileBarcodeScanningOptions.cs from ZXing github.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!