【问题标题】:Xamarin.iOS ZXing.Net.Mobile barcode scannerXamarin.iOS ZXing.Net.Mobile 条码扫描器
【发布时间】:2016-08-17 11:06:57
【问题描述】:

我正在尝试将条形码扫描仪功能添加到我的 xamarin.ios 应用程序。我是从 Visual Studio 开发的,我已经从 xamarin 组件商店添加了 Zxing.Net.Mobile 组件。

我已经按照示例所示实现了它:

ScanButton.TouchUpInside += async (sender, e) => {
            //var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
            //options.AutoRotate = false;
            //options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
            //    ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
            //};

            var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
            //scanner.TopText = "Hold camera up to barcode to scan";
            //scanner.BottomText = "Barcode will automatically scan";
            //scanner.UseCustomOverlay = false;
            scanner.FlashButtonText = "Flash";
            scanner.CancelButtonText = "Cancel";
            scanner.Torch(true);
            scanner.AutoFocus();

            var result = await scanner.Scan(true);
            HandleScanResult(result);
        };

void HandleScanResult(ZXing.Result result)
    {
        if (result != null && !string.IsNullOrEmpty(result.Text))
            TextField.Text = result.Text;
    }

问题是,当我点击扫描按钮时,捕获视图正确显示,但如果我尝试捕获条形码,则没有任何反应,并且扫描仪似乎无法识别任何条形码。

有人遇到过这个问题吗?我怎样才能让它工作?

提前感谢您的帮助!

【问题讨论】:

  • 你在这里试过吗? components.xamarin.com/gettingstarted/zxing.net.mobile有一个示例代码(我从来没有使用过条码扫描器)
  • 是的,我遵循了该示例代码,但它不起作用。我还尝试从 github repo 运行 ios 示例,但它也不起作用。可能是我的ipad 2的问题(我用这个来测试)?
  • 你能关注这个吗? blog.xamarin.com/…
  • 不幸的是,它与 xamarin 形式有关。我需要 che ios 版本 :(

标签: ios xamarin xamarin.ios zxing barcode-scanner


【解决方案1】:

我回答了一个类似的问题here。我无法扫描条形码,因为默认相机分辨率设置得太低。本案例的具体实现为:

ScanButton.TouchUpInside += async (sender, e) => {
        var options = new ZXing.Mobile.MobileBarcodeScanningOptions {
            CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
        };

        var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
        .
        .
        .
        scanner.AutoFocus();

        //call scan with options created above
        var result = await scanner.Scan(options, true);
        HandleScanResult(result);
    };

然后是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];
}

【讨论】:

  • 谢谢@bonetoad。这是唯一适用于 ZXing 3.10、Xamarin forms 5.0 和 iOS 11+ 的解决方法。
  • 谢谢,它也救了我! 09/21,lib 还是 3.1 beta,项目被放弃了?
  • 我不确定。看起来最近在 21 年 1 月 19 日,github 存储库上至少有一些活动:github.com/Redth/ZXing.Net.Mobile/releases/tag/3.1.0-beta2
猜你喜欢
  • 2018-10-29
  • 1970-01-01
  • 1970-01-01
  • 2014-05-26
  • 1970-01-01
  • 1970-01-01
  • 2012-01-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多