TWAIN Module API
Functions
twain.DIBToBMFile()
This method is used to convert a DIB (Device Independent Bitmap) to a windows
bitmap file format. The BMP file is either returned as a string, or written
to a file with the name given in the second argument.
Parameters
Name |
Description |
Default Value |
hBitmap |
A global handle as returned from the Source.XferImageNatively() function. |
mandatory |
FileName |
A string supplying a file name. |
If not passed, the BMP file will be returned as a string. |
This method returns a single value, which is either the BMP file as a string,
or None. On failure it raises the following exceptions:
twain.DIBToXBMFile()
This method is used to convert a DIB (Device Independent Bitmap) to an X-Windows
bitmap file format. The XBM file is either returned as a string, or written
to a file with the name given in the third argument.
Parameters
Name |
Description |
Default Value |
hBitmap |
A global handle as returned from the Source.XferImageNatively() function. |
mandatory |
Prefix |
A string supplying the prefix (XBM id). This is normally the file name
excluding the .xbm suffix. |
mandatory |
FileName |
A string supplying a file name. |
If not passed, the XBM file will be returned as a string. |
This method returns a single value, which is either the XBM file as a string,
or None. On failure it raises the following exceptions:
twain.GlobalHandleAllocate()
This method provides the application with access to the Windows Global Heap. It
allocates a handler of a specific size.
Parameters
Name |
Description |
Default Value |
lSize |
The size of the memory buffer required. |
mandatory |
This method allocates the required memory and returns a handle to the memory.
If the function fails, it returns None.
twain.GlobalHandleGetBytes()
This method provides the application with access to the Windows Global Heap. It
returns a specified number of bytes from the Global Heap location, identified
by the handle.
Parameters
Name |
Description |
Default Value |
Handle |
A handle returned by GlobalHandleAllocate(), or XferImageNatively(). |
mandatory |
Offset |
An integer giving the offset in the buffer at which to begin the read. |
mandatory |
Length |
The number of bytes to read from the buffer. |
mandatory |
This method returns a python string, which contains the identified data.
twain.GlobalHandlePutBytes()
This method provides the application with access to the Windows Global Heap. It
writes a python string to Global Heap location, identified
by the handle.
Parameters
Name |
Description |
Default Value |
Handle |
A handle returned by GlobalHandleAllocate(), or XferImageNatively(). |
mandatory |
Offset |
An integer giving the offset in the buffer at which to begin the read. |
mandatory |
Length |
The number of bytes to read from the buffer. |
mandatory |
Data |
A Python string containing the data to be written. |
mandatory |
This method does not return any values.
twain.GlobalHandleFree()
This method provides the application with access to the Windows Global Heap. It
releases the Global Heap location, identified by the handle.
Parameters
Name |
Description |
Default Value |
Handle |
A handle returned by GlobalHandleAllocate(), or XferImageNatively(). |
mandatory |
twain.Version()
Returns the version identifier for the Python TWAIN interface.
Variables
A large number of constants are defined in the TWAIN module. These are used with
various API calls. They are broken down by their prefixes, as follows:
Prefix |
Purpose |
ACAP_
| Audio Capabilities |
CAP_
| General Capabilities |
DAT_
| Describe the types of data structures |
DG_
| Identify Data Groups (i.e. images/audio) |
ICAP_
| Identify Image Capabilities |
MSG_
| Message Identifiers for communcations with Source |
TWAF_
| Audio File Formats |
TWAL_
| Alarm Codes |
TWBCOR_
| Barcode Rotation |
TWBD_
| Barcode Search Mode |
TWBO_
| Bit-order |
TWBR_
| Bit-depth Reduction |
TWBT_
| Barcode Type |
TWCB_
| Clear Buffesr |
TWCC_
| Condition Codes (errors) |
TWCP_
| Compression Options |
TWCY_
| Country Constants |
TWDE_
| Device Events |
TWDSK_
| de-skew |
TWDX_
| Duplication Options |
TWEI_
| Extended Image Information |
TWEJ_
| Not defined in specification* (appear to relate to ejection of
originals) |
TWFA_
| Feeded Alignment |
TWFF_
| File Formats (Image) |
TWFL_
| Flash Used |
TWFO_
| Feeder Order |
TWFR_
| Flip Rotation |
TWFS_
| File System |
TWFT_
| Filter Type |
TWFY_
| File System - File Type |
TWIF_
| Image Filter |
TWJC_
| Job Control |
TWLG_
| Language Ids |
TWLP_
| Light Path |
TWLS_
| Light Source |
TWMF_
| Memory Flags |
TWNF_
| Noise Filter |
TWON_
| Protocol Version Identifiers |
TWOR_
| Orientation |
TWOV_
| Overscan |
TWPA_
| Colour Palette types |
TWPCH_
| Extend Image (TWEI) Patch Codes |
TWPC_
| Planar/Chunky selection |
TWPF_
| Pixel Flavour |
TWPM_
| Printer Mode |
TWPR_
| Printer Codes |
TWPS_
| Power Supply |
TWPT_
| Pixel Type |
TWQC_
| Query Capability Options |
TWRC_
| Return Codes |
TWSS_
| Supported Sizes |
TWSX_
| Transfer Mechanism |
TWTY_
| TWAIN Primitive Types |
TWUN_
| Image Units |