gpt4 book ai didi

c# - ZXing.Net.Mobile 没有立即开始扫描

转载 作者:行者123 更新时间:2023-11-30 23:02:23 28 4
gpt4 key购买 nike

我有一个以 ScannerView 作为 MainPage 的页面。当我启动应用程序时,它无法扫描条形码。我必须将另一个页面设置为主页然后导航到扫描仪页面,然后它才能扫描条形码。或者锁定然后解锁手机,然后它就会开始扫描。

App.xaml.cs:

MainPage = new NavigationPage(new ScannerPage());

扫描仪页面.xaml:

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

扫描仪页面.xaml.cs:

public partial class ScannerPage : ContentPage
{
public ScannerPage ()
{
InitializeComponent ();

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

ScannerView.OnScanResult += (result) => Device.BeginInvokeOnMainThread(async () =>
{
ScannerView.IsAnalyzing = false;
await DisplayAlert("Scanned", result.Text, "Ok");
ScannerView.IsAnalyzing = true;
});
}
}

最佳答案

我最终以编程方式使用了以下代码:

    public static async Task ScanConnection()
{
MobileBarcodeScanningOptions options = new ZXing.Mobile.MobileBarcodeScanningOptions()
{
TryHarder = true,
PossibleFormats = new List<ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.QR_CODE }
};


MobileBarcodeScanner scanner = new ZXing.Mobile.MobileBarcodeScanner();

ZXing.Result result = await scanner.Scan(options);

if (result != null && !string.IsNullOrEmpty(result.Text))
{
...
}
}

您可以从派生页面中重写的 OnAppearing() 方法调用该代码。

关于c# - ZXing.Net.Mobile 没有立即开始扫描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50502484/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com