2017-03-20 2 views
0

Voici mon code:Numérisation de plusieurs pages à l'aide (py) twain

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) 

Je suppose que chaque acquire appelle une analyse au scanner, mais ce n'est pas le cas

Comment puis-je numériser plusieurs pages en utilisant pytwain?

Merci

Répondre

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 

Voilà comment je le fais dans mon forfait: https://github.com/spacemudd/webagent-scanner/blob/master/pyScanLib/twainLib.py