ここ

2017-03-20 3 views
0

をトウェインが私のコードです:ここ

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
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