繁体   English   中英

ZXing.net.mobile视图无法扫描条形码

[英]ZXing.net.mobile view can't scan barcodes

更新:这是硬件问题。 它可以在较新的手机上使用。

ZXing.Net.MobileZXing.Net.Mobile.Forms添加到项目中。

扫描仪视图和相机看起来不错。 闪光按钮起作用。 但是永远不会引发OnScanResult 尝试了各种DataMatrix,PDF417和QR码。

测试电话是HTC M9。

ScannerPage.xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
             x:Class="MyApp.ScannerPage">
    <ContentPage.Content>
        <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
            <zxing:ZXingScannerView
                x:Name="ScannerView"/>
            <zxing:ZXingDefaultOverlay
                x:Name="ScannerOverlay"
                TopText="Hold your phone up to the barcode"
                BottomText="Scanning will happen automatically"/>
        </Grid>
    </ContentPage.Content>
</ContentPage>

ScannerPage.xaml.cs

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ScannerPage : ContentPage
{
    public ScannerPage()
    {
        InitializeComponent();

        ScannerView.Options = new ZXing.Mobile.MobileBarcodeScanningOptions
        {
            PossibleFormats = new List<BarcodeFormat>
            {
                BarcodeFormat.DATA_MATRIX,
                BarcodeFormat.PDF_417,
                BarcodeFormat.QR_CODE
            },
            TryHarder = true
        };

        ScannerView.OnScanResult += (result) =>
        {
            var x = 3; // Breakpoint here, never hit

            Device.BeginInvokeOnMainThread(async () =>
            {
                // Stop analysis until we navigate away so we don't keep reading barcodes
                //ScannerView.IsAnalyzing = false;

                // Show an alert
                await DisplayAlert("Scanned Barcode", result.Text, "OK");
            });
        };

        ScannerOverlay.ShowFlashButton = ScannerView.HasTorch;
        ScannerOverlay.FlashButtonClicked += (se, ev) => ScannerView.ToggleTorch();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();
        ScannerView.IsAnalyzing = true;
        ScannerView.IsScanning = true;
    }

    protected override void OnDisappearing()
    {
        base.OnDisappearing();
        ScannerView.IsScanning = false;
    }
}

也许是硬件问题..低分辨率相机? 尝试使用更新的智能手机...

您也可以尝试使用“最简单”的条形码(code128,ean8,ean13 ...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM