c# - 如何在 iOS 10.2 上使用 xamarin forms + zxing 扫描驾照 (PDF417)

标签 c# xamarin xamarin.ios barcode zxing

我正在使用 Xamarin 表单编写 iOS 应用程序并使用 ZXing 库扫描条形码。我正在尝试读取驾照 (PDF417) 条形码,但图书馆无法识别该条形码。

如果我在 PossibleFormats 中包含 UPC 或其他条形码,它们将被正确扫描。

我还确定我尝试读取的条码是 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);
    }

最佳答案

几天前我遇到了这个完全相同的问题,并用以下方法修复了它。在 MobileBarcodeScanningOptions 类中,有一个名为 CameraResolutionSelectorCameraResolutionSelectorDelegate 类型的属性。您可以将其设置为从可用分辨率列表中返回更高的相机分辨率。所以我的 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 的源代码。

关于c# - 如何在 iOS 10.2 上使用 xamarin forms + zxing 扫描驾照 (PDF417),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42657211/

相关文章:

c# - 机器人框架中的文本格式

c# - 在 Xamarin.Forms 上使用 SkiaSharp 库绘制样条曲线(平滑路径)?

xamarin - 在 Xamarin Android 中的 MVVMCross 中从 View 模型中关闭键盘

ios - 简单 Estimote (iBeacon) Xamarin 示例不工作

ios - 如何在 Macbook 中的 iPhone 6s 模拟器上找到 SQLite 数据库?

ios - 来自 Visual Studio 的 Xamarin.ios Today 扩展

iphone - 使用 Monotouch 在 iPhone 中播放 MJPEG 流

c# - 如何在 Linux 命令行上通过 Mono 构建 C# 文件?

c# - CSS:使用宽度百分比定位子表?

c# - ServicedComponent 未在终结器中处理