【问题标题】:ZXing.Net.Mobile Sample.WindowsUniversal Sample Not ScanningZXing.Net.Mobile Sample.WindowsUniversal 样本未扫描
【发布时间】:2017-11-27 22:48:17
【问题描述】:

对此进行测试以将其合并到 Win 10 UWP 应用中以扫描一维条码(格式 39 和 128)。我通过 nuget 2.0.4.46 更新了最新版本。参考http://www.yortondotnet.com/2015/07/mobile-barcode-scanning-with-zxingnet.html 的帖子,关于 scan() 之前的一些选项设置,但没有运气。扫描仪(相机)打开但从未成功识别条形码扫描 - 或失败。似乎什么都没有发生。我已经包含了直接的、相关的示例代码以及一些选项修改以供审查。我已经让 Scandit API 工作,并打算尝试 Manateeworks,但两者都非常昂贵,而且不是一个选择。我正在 Surface Pro 3 (Win 10) 上开发,完成后该版本也将成为目标机器。

public sealed partial class MainPage : Page
{
    UIElement customOverlayElement = null;
    MobileBarcodeScanner scanner;

    public MainPage()
    {
        this.InitializeComponent();

        //Create a new instance of our scanner
        scanner = new MobileBarcodeScanner(this.Dispatcher);
        scanner.Dispatcher = this.Dispatcher;
    }

    private void buttonScanDefault_Click(object sender, RoutedEventArgs e)
    {
        //Tell our scanner to use the default overlay
        scanner.UseCustomOverlay = false;
        //We can customize the top and bottom text of our default overlay
        scanner.TopText = "Hold camera up to barcode";
        scanner.BottomText = "Camera will automatically scan barcode\r\n\r\nPress the 'Back' button to Cancel";

        // GWS Set Options
        var options = new MobileBarcodeScanningOptions();
        options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
            ZXing.BarcodeFormat.CODE_39, ZXing.BarcodeFormat.CODE_128
        };
        options.AutoRotate = false;
        options.TryHarder = false;
        options.TryInverted = false;

        //Start scanning
        scanner.Scan(options).ContinueWith(t =>
        {
            if (t.Result != null)
                HandleScanResult(t.Result);
        });
    }
    private void buttonScanContinuously_Click(object sender, RoutedEventArgs e)
    {
        //Tell our scanner to use the default overlay
        scanner.UseCustomOverlay = false;
        //We can customize the top and bottom text of our default overlay
        scanner.TopText = "Hold camera up to barcode";
        scanner.BottomText = "Camera will automatically scan barcode\r\n\r\nPress the 'Back' button to Cancel";

        // GWS Set Options
        var options = new MobileBarcodeScanningOptions();
        options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
            ZXing.BarcodeFormat.CODE_39, ZXing.BarcodeFormat.CODE_128
        };
        options.AutoRotate = false;
        options.TryHarder = false;
        options.TryInverted = false;

        //Start scanning
        scanner.ScanContinuously(options, async (result) =>
        {
            var msg = "Found Barcode: " + result.Text;

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                await MessageBox(msg);
            });
        });
    }
    async void HandleScanResult(ZXing.Result result)
    {
        string msg = "";

        if (result != null && !string.IsNullOrEmpty(result.Text))
            msg = "Found Barcode: " + result.Text;
        else
            msg = "Scanning Canceled!";

        await MessageBox(msg);

    }

}

【问题讨论】:

  • 您是否尝试过将 try hard 更改为 true ?

标签: win-universal-app zxing barcode-scanner


【解决方案1】:

西蒙,

我也有同样的问题。我用最新的nuget 2.1.47测试了你的代码,问题依然存在。

您需要从Github 下载最新版本并将以下项目(或 DLL)添加到您的项目中:

ZXing.Net (project: zxing.portable.csproj)
ZXing.Net.Mobile.Core
ZXing.Net.Mobile.WindowsUniversal

我已经测试了您的代码,它运行良好。我希望这会有所帮助。

干杯, 山姆

【讨论】:

    【解决方案2】:

    我认为您正在测试的硬件存在问题。 Surface Pro 3 (Win 10) does not have an auto focus camera。我从未使用我的 Surface Pro 3 成功使用 ZXing 进行扫描,而相同的应用程序在我的其他 Windows 10 设备上运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-26
      • 1970-01-01
      • 2018-10-29
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 2021-05-25
      相关资源
      最近更新 更多