1.5.14. fejezet, Szkenner kezelés

Kapcsolódó hivatkozások

WIA ActiveX objektum használata

PyWin32 telepításe

python -m pip install pywin32

Minta kód:

import win32com.client, os
 
WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}"
SCANNER_1 = r"{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000"
def acquire_image_wia():
    device_manager = win32com.client.Dispatch("WIA.DeviceManager")
    if device_manager.DeviceInfos.Count > 0:
        #device = device_manager.DeviceInfos.Item(1).Connect()
        #device_info = device_manager.DeviceInfos.Item(1)
        device_info = device_manager.DeviceInfos(SCANNER_1)
        device = device_info.Connect()
        for prop in device_info.Properties: print(prop.Name + " : " + str(prop.Value))
        for item in device.Items:
            image = item.Transfer(WIA_IMG_FORMAT_PNG)
            f_name = 'wia-test.png'
            if os.path.exists(f_name): os.remove(f_name)
            image.SaveFile(f_name)
 
acquire_image_wia()