xamarin - ZXing.Mobile - 如何更改相机扫描仪的尺寸?

标签 xamarin configuration xamarin.forms zxing barcode-scanner

更新:

我尝试在名为 OpenCameraScanner 的 App.cs 方法中实现此功能(您可以通过单击要扫描的页面上的按钮来调用此方法):

App.cs
------------------------------------------------
public static ZXingScannerPage ScanPage;
public static ZXing.Result ScanResult;

public static async void OpenCameraScanner()
{
    ScanPage = new ZXingScannerPage(customOverlay: customOverlay);
    ScanPage.OnScanResult += (result) =>
    {
        ScanPage.IsScanning = false;
        ScanResult = result;

        Device.BeginInvokeOnMainThread(() =>
        {
            App.CurrentApp.CurrentPage.Navigation.PopModalAsync();
            App.CurrentApp.CurrentPage.DisplayAlert("Scanned Barcode", result.Text, "OK");
        });
    };
    var scanPage = new NavigationPage(ScanPage);
    await App.CurrentApp.CurrentPage.Navigation.PushModalAsync(ScanPage);
}

但是,当调用此方法时,打开的屏幕是空白的白色,并且您看不到其后面的相机 View 。不知道为什么?


我在 Xamarin.Forms 项目(目前适用于 iOS)中使用 ZXing.Mobile 在 iPad 上实现相机扫描功能。

目前,我可以很好地使用以下两行代码:

var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan();

但是,当相机打开进行扫描时,它会占据整个 iPad 屏幕,这确实很大。

问题:有没有办法调整相机覆盖层的大小? (这样就不是全屏)

我看到 scanner.Scan() 方法采用 ZXing.Mobile.MobileBarcodeScanningOptions 类型的 optional 参数 - 我尝试使用它,但唯一的可能的相关选项有一个 CameraResolutionSelector - 但我很难找到任何相关文档。

最佳答案

有一个 ZXing 示例应用程序,演示如何将 ZXingScannerViewZXingDefaultOverlay 嵌入到 Xamarin.FormGrid 中:

https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Forms/Core/CustomScanPage.cs

public CustomScanPage () : base ()
{
    zxing = new ZXingScannerView
    {
        HorizontalOptions = LayoutOptions.FillAndExpand,
        VerticalOptions = LayoutOptions.FillAndExpand,
        AutomationId = "zxingScannerView",
    };
    zxing.OnScanResult += (result) => 
        Device.BeginInvokeOnMainThread (async () => {

            // Stop analysis until we navigate away so we don't keep reading barcodes
            zxing.IsAnalyzing = false;

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

            // Navigate away
            await Navigation.PopAsync ();
        });

    overlay = new ZXingDefaultOverlay
    {
        TopText = "Hold your phone up to the barcode",
        BottomText = "Scanning will happen automatically",
        ShowFlashButton = zxing.HasTorch,
        AutomationId = "zxingDefaultOverlay",
    };
    overlay.FlashButtonClicked += (sender, e) => {
        zxing.IsTorchOn = !zxing.IsTorchOn;
    };
    var grid = new Grid
    {
        VerticalOptions = LayoutOptions.FillAndExpand,
        HorizontalOptions = LayoutOptions.FillAndExpand,
    };
    grid.Children.Add(zxing);
    grid.Children.Add(overlay);

    // The root page of your application
    Content = grid;
}

关于xamarin - ZXing.Mobile - 如何更改相机扫描仪的尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38662322/

相关文章:

c# - 如何从 Xamarin(Android 和 iOS)使用 OpenCV?

c# - Xamarin Android : Failed to resolve type MvvmCross. Core.ViewModels.IMvxAppStart

c# - Xamarin 表格 : Image height request ignored inside frame inside relative layout

visual-studio-2010 - 使用 IIS 的 Web 项目,但我收到有关 IISExpress 配置的错误

xamarin - 使用 Xamarin Forms 的可用 wifi 连接列表

xaml - 多个 BindingContext 在同一个 ContentPage 上,两个不同的 View ?

ssl - slapd : result. c:813: slap_send_ldap_result: 断言 `!((rs->sr_err)<0)' 失败

configuration - Octave :禁用 Octave 工作区崩溃文件

azure - 何时使用 MSAL AcquireTokenSilentAsync

xaml - Xamarin 检测输入键 MVVM