这是我的代码:
import twain
for i in range(10):
twain.acquire(str(i) + ".jpg", ds_name=b"B110,192.168.1.112 TWAIN",
dpi=200, pixel_type='gray', bpp=8, show_ui=False)
我假设每个acquire
都会向扫描仪调用扫描,但情况并非如此
如何使用pytwain扫描多个页面?
由于
答案 0 :(得分:0)
def multiScan(self):
""" Scan and return an array of PIL objects
If no images, will return an empty array
"""
self.scanner.RequestAcquire(0, 1)
images = []
handles = []
try:
handle, more = self.scanner.XferImageNatively()
handles.append(handle)
except twain.excDSTransferCancelled:
return []
while more != 0:
try:
handle, more = self.scanner.XferImageNatively()
handles.append(handle)
except twain.excDSTransferCancelled:
more = 0
for handle in handles:
images.append(Image.open(StringIO(twain.DIBToBMFile(handle))))
twain.GlobalHandleFree(handle)
return images
这就是我在我的包中做到的:https://github.com/spacemudd/webagent-scanner/blob/master/pyScanLib/twainLib.py