Xamarin ios ZXING 扫描仪不分析 QR

发布于 2025-01-12 03:28:05 字数 1780 浏览 2 评论 0原文

我使用的是 Iphone 10 和 ios 15.3.1,Zxing 版本 = 2.4.1,在 Windows 中编译 xamarin 项目。我一直在尝试使用 zxing 为 ios android 制作一个 qr 扫描仪,但是当我在 ios 中运行我的应用程序时,它不会进入 onResult 事件。我尝试了很多方法来做到这一点,但似乎没有任何效果。摄像机显示了,但结果永远不会是真实的。有人知道为什么会发生这种情况吗?我还尝试了其他开发人员使用 zxing 的应用程序,但它也不起作用。但是当我用相机应用程序扫描时它可以工作。

        async void OnButtonClickedAsync(object sender, System.EventArgs e)
    {
        var options = new ZXing.Mobile.MobileBarcodeScanningOptions
        {
            CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
        };
        MobileBarcodeScanner scanner = new MobileBarcodeScanner();
        //scanner.TopText = "Hold camera up to barcode to scan";
        //scanner.BottomText = "Barcode will automatically scan";
        //scanner.UseCustomOverlay = false;
        scanner.FlashButtonText = "Flash";
        scanner.CancelButtonText = "Cancel";
        
        scanner.Torch(true);
        scanner.AutoFocus();
       
        var result = await scanner.Scan(options);
        HandleScanResult(result);
    }

    void HandleScanResult(ZXing.Result result)
    {
        if (result != null && !string.IsNullOrEmpty(result.Text))
            scanResultText.Text = result.Text;
            
    }
    CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
    {
        //Don't know if this will ever be null or empty
        if (availableResolutions == null || availableResolutions.Count < 1)
            return new CameraResolution() { Width = 800, Height = 600 };

        //Debugging revealed that the last element in the list
        //expresses the highest resolution. This could probably be more thorough.
        return availableResolutions[availableResolutions.Count - 1];
    }

i'm using an Iphone 10 with ios 15.3.1,Zxing version = 2.4.1, compiling the xamarin project in windows. I been trying to make a qr scanner with zxing for ios android, but when i run my app in ios, it won't go to the onResult event. I've tried with a lot of methods of doing this, but nothing seems to work. The camera shows, but the result never comes truh. ¿Does someone have any idea why this is happening? I also tried apps from other devs that are using zxing and it also dosen't work. but when i scan with the camera app it works.

        async void OnButtonClickedAsync(object sender, System.EventArgs e)
    {
        var options = new ZXing.Mobile.MobileBarcodeScanningOptions
        {
            CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
        };
        MobileBarcodeScanner scanner = new MobileBarcodeScanner();
        //scanner.TopText = "Hold camera up to barcode to scan";
        //scanner.BottomText = "Barcode will automatically scan";
        //scanner.UseCustomOverlay = false;
        scanner.FlashButtonText = "Flash";
        scanner.CancelButtonText = "Cancel";
        
        scanner.Torch(true);
        scanner.AutoFocus();
       
        var result = await scanner.Scan(options);
        HandleScanResult(result);
    }

    void HandleScanResult(ZXing.Result result)
    {
        if (result != null && !string.IsNullOrEmpty(result.Text))
            scanResultText.Text = result.Text;
            
    }
    CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
    {
        //Don't know if this will ever be null or empty
        if (availableResolutions == null || availableResolutions.Count < 1)
            return new CameraResolution() { Width = 800, Height = 600 };

        //Debugging revealed that the last element in the list
        //expresses the highest resolution. This could probably be more thorough.
        return availableResolutions[availableResolutions.Count - 1];
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少跟Wǒ拽 2025-01-19 03:28:05

我用mac编译的,运行得很好,一定是windows上的Visual Studio的一个bug。

I compiled using a mac and it worked fine, must be a bug of visual studio on windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文