通过zxing打开相机进行二维码扫描时,如果正确扫描二维码却显示白屏,则会出现相机白屏?
这是我的代码:
namespace Kefi.Controls
{
public class CustomScanPage : ContentPage
{
ZXingScannerView zxing;
public CustomScanPage() : base()
{
zxing = new ZXingScannerView
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
NavigationPage.SetHasNavigationBar(this,false);
zxing.OnScanResult += (result) =>
Device.BeginInvokeOnMainThread(() =>
{
zxing.IsAnalyzing = false;
zxing.IsScanning = false;
MessagingCenter.Send(result, "Scanresult");
});
var grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
}
protected override void OnAppearing()
{
base.OnAppearing();
zxing.Options.DelayBetweenAnalyzingFrames = 5;
zxing.Options.DelayBetweenContinuousScans = 5;
zxing.IsScanning = true;
}
protected override void OnDisappearing()
{
zxing.IsScanning = false;
base.OnDisappearing();
}
}
}
答案 0 :(得分:1)
您甚至没有将scannerView
添加到contentPage,因此不会显示。添加一个简单的StackLayout
来容纳scannerView
,然后将其设置为Content
的{{1}}:
ContentPage
或者您可以自定义xaml中的ScannerView,请在此处查看博客:scanning-generating-barcodes-zxing
让我知道它是否对您有用。