Python 通过pytwain 2.0对含TWAIN 驱动的扫描仪设备进行二次开发,支持Python 3
第一步,安装Pytwain2.0
通过 pip install pytwain
第二步,输入以下示例代码
import twain
sm = twain.SourceManager(0)
ss = sm.OpenSource()
ss.RequestAcquire(0,0)
rv = ss.XferImageNatively()
if rv:
(handle, count) = rv
twain.DIBToBMFile(handle, 'image.bmp')
该代码默认Python2.7可以运行,并调出扫描仪选择窗口,不会报
twain.excSMLoadFileFailed: Could not find module ‘twain_32.dll’ (or one of its dependencies). Try using the full path with constructor syntax.
错误。
第三步,下载软件并集成64位驱动,支持Python3及以上
如果要支持Python3以上版本,仍需要下载“twain-dsm”,以支持64位系统
下载地址为:“https://download.csdn.net/download/wwwihpccn/56342941”
将下载文件解压下来,将Windows下32及64文件夹拷贝到开发目录下,并通过sm = twain.SourceManager(0, dsm_name=r’dsm_020400\windows\64\TWAINDSM.dll’) 指定64位dll文件所在位置。