xamarin - Xamarin形成条形码扫描仪

标签 xamarin xamarin.forms zxing barcode-scanner

我找不到Xamarin表格条形码扫描仪的任何有效来源。使用zxing库是否有Xamarin表格条形码扫描仪的工作样本?

最佳答案

您可以尝试下面的代码。将zxing库/组件添加到解决方案中的所有项目

public class Home : ContentPage
{
    string message = "";
    public Home()
    {
        //Intialize the button
        Button btnScan = new Button
        {
            Text = "Start Scan",
            BackgroundColor = Color.FromRgb(207, 197, 159),
            TextColor = Color.White,
            BorderRadius = 5,
            TranslationY = 120
        };
        //Attach the click event
        btnScan.Clicked += btnScan_Clicked;

        this.Content = new StackLayout
        {
            BackgroundColor = Color.FromRgb(150, 172, 135),
            Spacing = 10,
            Padding = 25,
            Children =
            {
                btnScan
            }
        };
    }

    async void btnScan_Clicked(object sender, EventArgs e)
    {
        var scanner = new MobileBarcodeScanner();
        scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away";
        scanner.BottomText = "Wait for the barcode to automatically scan!";

        //This will start scanning
        ZXing.Result result = await scanner.Scan();

        //Show the result returned.
        HandleResult(result);
    }

    void HandleResult(ZXing.Result result)
    {
        var msg = "No Barcode!";
        if (result != null)
        {
            msg = "Barcode: " + result.Text + " (" + result.BarcodeFormat + ")";
        }

        DisplayAlert("", msg, "Ok");
    }
}

关于xamarin - Xamarin形成条形码扫描仪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37406288/

相关文章:

xamarin.android - .NET 4.5 PCL 中的异步/等待面向 Android 的 Mono?

android - Xamarin.Forms 项目中已添加 NuGet 包

设置为可聚焦后,带有 Xamarin EditText 的 Android 无法使用

xamarin.forms - 如何一次关闭多个(所有)模态?

java - 将 ZXing 集成到我的应用程序中

c# - 安装 Xamarin IOS.Setup 和 Android.Setup 时 "' 1.0.0 ' is not a valid short file name"

c# - 在绑定(bind)到 ListView 之前修改 ViewModel 的属性

c# - Xamarin 表单 : how to implement platform specific code

android - 为 android 项目构建库 ZXing

android - 如何在 Android Studio 中修复 'Duplicate classes'