uwp - 在 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 包几乎没有任何文档。
这是我第一次在这里问问题,如果您需要更多代码或直接说出来。我需要让它工作,谢谢。
解决方案
NotifyUser 方法是一个自定义的方法,它总是被调用来更新 UI 以显示通知消息。通常,从静态Current字段返回的 MainPage 实例上的各个场景 XAML 页面中调用此方法。NotifyUser 采用 NotifyType 类型的参数。您可以在此处找到 NotifyUser 方法的源代码。
至于ScannerDataItem类,也是一个自定义类,用于存储扫描仪设备信息,需要定义扫描仪设备的属性。
推荐阅读
- spring - Spring批处理远程分区| 可以在没有完成从属步骤的情况下完成主步骤
- google-sheets-formula - 新行的脚本并复制根据行索引自动增加的公式?
- javascript - 如何生成名称的选择下拉列表并在 javascript 或 jquery 中使用 optgroup 对它们进行分组?
- python - 错误 ValueError:执行字符串估计器时 int () 以 10 为底的无效文字。火车 (input_fn=train_input_fn)
- amazon-web-services - 无服务器部署到暂存域名
- c - 如何将链表作为函数参数发送
- python - ctypes.CDLL() 和 ctypes.cdll.LoadLibrary() 有什么区别?
- apache-spark - 仅使用单个元素的 RDD 上的 PySpark Reduce
- python - 如何根据原始数据框的不同类创建新数据框?
- javascript - 发送请求以从 adobe XD 插件中的 url 下载 .zip