介绍
@nodert-win8.1/windows.devices.scanners 是一个适用于 Windows 系统的扫描仪设备控制 npm 包。使用它可以实现对扫描仪设备的控制、获取设备信息、获取设备扫描后的数据等操作。
安装
使用 npm 可以很方便地安装该包:
npm install @nodert-win8.1/windows.devices.scanners
使用方法
1. 引入包
使用 require 导入包:
const ScannerDevice = require('@nodert-win8.1/windows.devices.scanners');
2. 初始化
使用 ScannerDevice.getDeviceSelector() 获取设备过滤条件,然后使用 ScannerDevice.getDefaultAsync() 获取默认设备,并进行初始化:
ScannerDevice.fromIdAsync(ScannerDevice.getDefaultId()).then((scanner) => { // 此处可以对 scanner 进行操作 }, (error) => { console.error('初始化扫描仪设备失败:', error); });
3. 获取设备信息
可以使用 scanner.getDeviceInformation() 获取设备信息:
-- -------------------- ---- ------- ------------------------------------------------------- -- - -------------------- ------------------------ --------------------- -------------------------- -------------------- ----------------------------------- ----------------------- ------------------------------------------- ---------------------- -------------------------------- -- ------- -- - -------------------------- ------- ---
4. 扫描
使用 scanner.acquireImage() 开始扫描,并传入一些参数:
-- -------------------- ---- ------- ----- ------------- - ------------------------------------- -- -------------- ----- ------------- - ---------------------------------- -- ---------------- ----- ------------ - ------------------------------ -- ------ ----- ------- - ---- -- ----- ----------------------------------- -------------- ------------- --------------------- -- - -------------------- ------- -- ------------------- -- ------- -- - ---------------------- ------- ---
5. 其他方法
ScannerDevice 还提供了许多其他有用的方法,比如:
- scanner.getSupportedPageSizeList():获取设备支持的纸张大小列表。
- scanner.getSupportedResolutionList():获取设备支持的分辨率列表。
- scanner.getSupportedScanMediaTypes():获取设备支持的扫描媒体类型列表。
示例代码
-- -------------------- ---- ------- ----- ------------- - --------------------------------------------------- ---------------------------------------------------------------------- -- - ----------------------- -- ------ ------------------------------------------------------- -- - -------------------- ------------------------ --------------------- -------------------------- -------------------- ----------------------------------- ----------------------- ------------------------------------------- ---------------------- -------------------------------- -- ------- -- - -------------------------- ------- --- -- ---- ----- ------------- - ------------------------------------- -- -------------- ----- ------------- - ---------------------------------- -- ---------------- ----- ------------ - ------------------------------ -- ------ ----- ------- - ---- -- ----- ----------------------------------- -------------- ------------- --------------------- -- - -------------------- ------- -- ------------------- -- ------- -- - ---------------------- ------- --- -- ------- -- - ---------------------------- ------- ---
总结
@nodert-win8.1/windows.devices.scanners 是一个非常有用的 npm 包,它可以帮助开发者轻松地实现对 Windows 系统下的扫描仪设备的控制和操作。本文介绍了它的使用方法,希望对读者有所帮助。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60066bce967216659e244c4a