首页 > 解决方案 > 在 UWP 和 WASM 中扫描文档

问题描述

我的老板一周前告诉我,我们需要能够列出可用的扫描仪设备并选择其中一个来扫描 UNO PLATFORM 中的文档。我们主要需要为 Wasm 和 Uwp 工作。我尝试使用 Windows.Devices.Scanners 和 Windows.Devices.Enumeration 因为我阅读了这个微软文档https://github.com/MicrosoftDocs/windows-uwp/blob/docs/windows-apps-src/devices-sensors/scan -from-your-app.md(在 UNO 项目和 UWP 项目中尝试过):

private async void OnScannerAdded(DeviceWatcher sender, DeviceInformation deviceInfo)
        {
            await
            MainPage.Current.Dispatcher.RunAsync(
                  Windows.UI.Core.CoreDispatcherPriority.Normal,
                  () =>
                  {
                      MainPage.Current.NotifyUser(String.Format("Scanner with device id {0} has been added", deviceInfo.Id), NotifyType.StatusMessage);

                 // search the device list for a device with a matching device id
                 ScannerDataItem match = FindInList(deviceInfo.Id);

                 // If we found a match then mark it as verified and return
                 if (match != null)
                      {
                          match.Matched = true;
                          return;
                      }

                 // Add the new element to the end of the list of devices
                 AppendToList(deviceInfo);
                  }
            );
        }

但是,当我复制列出所有扫描仪设备的代码时,我遇到了一些错误,并且无法构建项目。特别是这两行:

MainPage.Current.Dispatcher.RunAsync 和另一个从 MainPage 调用 Current(它显示:mainpage 不包含 current 的定义。)

另一种是 ScannerDataItem match = FindInList(deviceInfo.Id); (即使我使用自述文件开头指定的文档编写了这两个,也找不到 ScannerDataItem 类)。

我的老板告诉我,他在几年前使用 Twain 和 WIA 做过,但我找不到 Visual Studio 2019 的任何信息,而且使用 Twain 的 nugets 包几乎没有任何文档。

这是我第一次在这里问问题,如果您需要更多代码或直接说出来。我需要让它工作,谢谢。

标签: uwpuno-platform

解决方案


NotifyUser 方法是一个自定义的方法,它总是被调用来更新 UI 以显示通知消息。通常,从静态Current字段返回的 MainPage 实例上的各个场景 XAML 页面中调用此方法。NotifyUser 采用 NotifyType 类型的参数。您可以在此处找到 NotifyUser 方法的源代码。

至于ScannerDataItem类,也是一个自定义类,用于存储扫描仪设备信息,需要定义扫描仪设备的属性。


推荐阅读