Previous Up Next Guide

Transfer Mechanisms

TWAIN provides three mechanisms for passing images back to the application. These are 'Native', 'File' and 'Memory'. The twainmodule only supports two of these, 'Native' and 'File'.

Native Image Transfer

All TWAIN sources must support 'Native' mode image transfer.

In native mode transfer, the TWAIN source places the image in a Windows shared memory area called the Global Heap. The TWAIN source sends the handle to that memory area to our application. Our application can connect to the memory area using the handle.

The Native Image buffer is always in 'DIB' (device independent bitmap) format on Windows. DIB files cannot be displayed directly in Python. The twain module provides a function (DIBtoBMFile()) to convert the file to a Windows Bitmap File, which can be loaded into an Image. The twain module also provides a function (DIBtoXBMFile()), which converts the file to an XBM (X-windows bitmap) format, which can be displayed in a Tk label.

Once the image has been processed, the application must 'free' the handle, using the GlobalHandleFree() function. Otherwise the memory will not be available to any Windows Applications.

Methods

File Based Transfer

TWAIN sources are not required to support File Based transfer. However, it is recommended. You can determine whether file based transfer is supported by your TWAIN source, by using the ICAP_XFERMECH capability. The values for this capability are defined by the TWSX_ constants.

In File based transfer, the TWAIN source places the image into a windows disk file. Once the transfer has been completed the file exists. The application is responsible for the file and should provide house-keeping functions for the files.

The application can specify both the filename and the file format prior to commencing the transfer. The available file formats for your TWAIN source can be retrieved using the ICAP_IMAGEFILEFORMAT capability. The file format and name can both be specified using the SetXferFileName method.

Methods


Previous Up Next Guide