UWP BarcodeScanner预览:CaptureElement不显示任何预览 [英] UWP BarcodeScanner Preview: CaptureElement doesn't show any Preview

查看:115
本文介绍了UWP BarcodeScanner预览:CaptureElement不显示任何预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CaptureElements显示奇怪的行为.当我将实例化的MediaCapture设置为CaptureElements源,然后调用MediaCapture.StartPreviewAsync()时,CaptureElement不显示任何内容.

My CaptureElements are showing strange behavior. When I set a instantiated MediaCapture as the CaptureElements Source and then call MediaCapture.StartPreviewAsync() the CaptureElement doesn't show anything.

我在LoginPage上有一个功能正常的BarcodeScanner的应用程序(主应用程序). ->有效!

I have one Application (main-app) with a functional BarcodeScanner on the LoginPage. -> Works!

然后我想将相同的代码进行少量修改复制到SettingsPage,以便在连接多个摄像机的情况下可以设置默认摄像机. ->不起作用

Then I wanted to copy the same code to the SettingsPage with small modifications so in case of several attached cameras, the default one can be set. -> Doesn't work

然后,我尝试在远程调试器的帮助下,在与我的计算机具有相同Windows 10版本的其他Windows平板电脑上运行main-app(请记住,登录屏幕上的BarcodeScanner在我的计算机上可以运行). ->不起作用

Then I tried to run the main-app with the help of the remote debugger on other windows tablets with same Windows 10 Version as my machine (keep in mind, that the BarcodeScanner on the Login-Screen works on my machine). -> doesn't work

由于这些失败,我将正在运行的代码从主应用程序LoginPage复制到了一个全新的解决方案(称为test-app),其设置与原始解决方案相同.我什至尝试引用相同的Dll,实现相同的设计模式等. ->不起作用

Because of these failures I copied the running code from the main-apps LoginPage to a completely new solution (lets call it test-app) with the same settings as the original one. I even experimented with referencing the same Dlls, implementing the same design pattern etc. -> doesn't work

我的机器: 赢10 Pro 1809版 内部版本17763.652

My Machine: Win 10 Pro Version 1809 Build 17763.652

DevEnv: MS Visual Studio 2019专业版 版本16.1.6

DevEnv: MS Visual Studio 2019 Pro Vers. 16.1.6

作为最低要求的Windows版本,我选择了Build 16229和 我的目标版本是Build 17763(我的系统Win版本)

As minimum required Windows Version I selected Build 16229 and my target Version is Build 17763 (my systems Win version)

寡妇设置"中的允许应用程序访问您的相机"选项已打开,因此所有应用程序都可以访问相机.

The "Allow apps to access your camera"-Option in the Widows Settings is switched to ON, so all apps are allowed to access the camera.

Xaml

    <Page
        x:Class="QrCodeTest.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:QrCodeTest"
        xmlns:vm="using:QrCodeTest.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">

        <Page.DataContext>
            <vm:TestViewModel x:Name="ViewModel" />
        </Page.DataContext>

        <ScrollViewer>
            <StackPanel>
                <Button Content="Start Preview" HorizontalAlignment="Center" Click="Button_Click" Margin="5" />

                <CaptureElement x:Name="capturePreview" HorizontalAlignment="Center" Stretch="Uniform" Width="0" Height="0" Margin="10" />

                <Button Content="Stop Preview" HorizontalAlignment="Center" Click="Button_Click_1" Margin="5" />

                <TextBlock Text="{Binding Etikett, Mode=TwoWay}" HorizontalAlignment="Center" Margin="5" />
            </StackPanel>
        </ScrollViewer>
    </Page>

CodeBehind

CodeBehind

private BarcodeScanner scanner { get; set; }
private ClaimedBarcodeScanner claimedScanner { get; set; }
private MediaCapture captureManager { get; set; }

internal async Task StartScannerAsync () {
            capturePreview.Visibility = Visibility.Visible;
            capturePreview.Width = 400; capturePreview.Height = 300;

            scanner = null;
            scanner = await DeviceHelpers.GetFirstDeviceAsync(BarcodeScanner.GetDeviceSelector(connectionTypes), async (id) => await BarcodeScanner.FromIdAsync(id));

            if (scanner != null) {
                captureManager = new MediaCapture();
                claimedScanner = await scanner.ClaimScannerAsync();

                if (claimedScanner != null) {
                    claimedScanner.ReleaseDeviceRequested += claimedScanner_ReleaseDeviceRequested;
                    claimedScanner.DataReceived += claimedScanner_DataReceived;

                    claimedScanner.IsDecodeDataEnabled = true;
                    IReadOnlyList<uint> supportedSymbologies = await scanner.GetSupportedSymbologiesAsync();

                    foreach (uint symbology in supportedSymbologies) {
                        listOfSymbologies.Add(new SymbologyListEntry(symbology));
                    }

                    await claimedScanner.EnableAsync();

                    MediaCaptureInitializationSettings _captureInitSettings = new MediaCaptureInitializationSettings {
                        VideoDeviceId = scanner.VideoDeviceId,
                        StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo,
                        PhotoCaptureSource = PhotoCaptureSource.VideoPreview
                    };

                    await captureManager.InitializeAsync(_captureInitSettings);
                    capturePreview.Source = captureManager;

                    try {
                        // Change to false, in case you wanna compare different methods of doing the same
                        bool Like_MP_PAT_UWP = false;

                        if (Like_MP_PAT_UWP) {
                            await capturePreview.Source.StartPreviewAsync();
                            await claimedScanner.StartSoftwareTriggerAsync();
                        } else {


                            LocalDataContext.Etikett = "await captureManager.StartPreviewAsync();";
                            await captureManager.StartPreviewAsync();
                            await claimedScanner.StartSoftwareTriggerAsync();
                            Thread.Sleep(2000);
                            await claimedScanner.StopSoftwareTriggerAsync();
                            await captureManager.StopPreviewAsync();

                            LocalDataContext.Etikett = "await capturePreview.Source.StartPreviewAsync();";
                            await capturePreview.Source.StartPreviewAsync();
                            await claimedScanner.StartSoftwareTriggerAsync();
                            Thread.Sleep(2000);
                            await claimedScanner.StopSoftwareTriggerAsync();
                            await capturePreview.Source.StopPreviewAsync();

                            LocalDataContext.Etikett = "await claimedScanner.ShowVideoPreviewAsync();";
                            await claimedScanner.ShowVideoPreviewAsync();
                            await claimedScanner.StartSoftwareTriggerAsync();
                            Thread.Sleep(2000);
                            await claimedScanner.StopSoftwareTriggerAsync();
                            claimedScanner.HideVideoPreview();
                        }

                    } catch (Exception e) {
                        Exception x = e; displayRequest.RequestRelease();
                    } finally {
                        LocalDataContext.Etikett = string.Empty;
                    }

                }
            }
        }

ViewModel:

ViewModel:

public class TestViewModel: INotifyPropertyChanged {
        public static TestViewModel Instance { get; set; }

        private string _Etikett;
        public string Etikett { get { return _Etikett; } set { _Etikett = value; NotifyPropertyChanged(); } }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged ([CallerMemberName] String propertyName = "") {
            //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

            if (PropertyChanged != null) {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }
}

为了比较解决方案,代码等,我已经浪费了4个工作日.以上代码是从test-app复制而来的,但它与主应用程序LoginPage上的代码基本相同("if (Like_MP_PAT_UWP){...}".

I've wasted already 4 working days just to compare the solutions, the codes etc. The above code was copied from the test-app but it's mostly identical to the one on the main-apps LoginPage (except for the "if (Like_MP_PAT_UWP) {...}".

每个提示都是欢迎的.

谢谢.

推荐答案

问题是Kaspersky Endpoint Security的高级威胁防护/主机入侵防御"设置.它阻止了开发硬盘驱动器(即平板电脑或网络驱动器)上的所有外部应用访问相机(Dev-Drive =受信任的区域").

The Problem was Kaspersky Endpoint Security's "advanced Threat Protection/host intrusion prevention"-setting. It prevented ALL apps outside from our dev-harddrive (i. e. on our tablets or from our network-drive) to access the camera (Dev-Drive = "Trusted Zone").

有必要在整个环境中重新配置Kaspersky Endpoint Security中的功能(将必要的位置/客户端声明为受信任的区域).

It was necessary to reconfigure that feature in Kaspersky Endpoint Security for the whole environment (declare necessary locations/clients as a trusted zone).

希望,这可能会帮助遇到类似问题的人,或者至少给某人一些提示.

Hope, this might help someone with a similar problem or at least give a hint to someone.

这篇关于UWP BarcodeScanner预览:CaptureElement不显示任何预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆