当通过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();
}
}
}
发布于 2019-07-04 07:18:49
您甚至没有将scannerView
添加到contentPage,所以它不会显示。添加一个简单的StackLayout
来保存scannerView
,然后将其设置为ContentPage
的Content
public CustomScanPage()
{
zxing = new ZXingScannerView
{
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
BackgroundColor = Color.Orange
};
NavigationPage.SetHasNavigationBar(this, false);
zxing.OnScanResult += (result) =>
Device.BeginInvokeOnMainThread(() =>
{
zxing.IsAnalyzing = false;
zxing.IsScanning = false;
MessagingCenter.Send(result, "Scanresult");
});
var layout = new StackLayout();
layout.BackgroundColor = Color.Red;
layout.Children.Add(zxing);
Content = zxing;
}
或者,您也可以在xaml中自定义scannerView,请参阅此处的博客:scanning-generating-barcodes-zxing
如果它对你有效,请让我知道。
https://stackoverflow.com/questions/56869079
复制相似问题