ZXing.Net.Mobile Sample.WindowsUniversal Sample Not Scanning

时间:2016-05-06 18:47:22

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

测试此内容以合并到Win 10 UWP应用程序中以扫描1D条形码(格式39和128)。我通过nuget 2.0.4.46更新了最新版本。 http://www.yortondotnet.com/2015/07/mobile-barcode-scanning-with-zxingnet.html上的参考帖子,关于扫描前的一些选项设置()没有运气。扫描仪(相机)打开但从未成功识别条形码扫描 - 或者说无法识别。似乎没有任何事情发生。我已经包含了直接的,相关的示例代码以及一些选项修改以供审阅。我已经使用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);

    }

}

2 个答案:

答案 0 :(得分:0)

西蒙,

我有完全相同的问题。我用最新的nuget 2.1.47测试了你的代码,问题仍然存在。

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

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

我已经测试了你的代码,它运行正常。我希望这有帮助。

干杯, 萨姆

答案 1 :(得分:0)

我认为您正在测试的硬件中存在问题。 Surface Pro 3(Win 10)enter image description here。我使用Surface Pro 3从未成功使用ZXing进行扫描,而同一应用程序在我的其他Windows 10设备上运行良好。