Handling Extended Image Information
Some image devices support getting information as to imprinter strings, barcode detection, patch code information, and other specialized information concerning the acquired image.
To retrieve this information, the TWAIN Source usually supports Extended Image Information. In general, the extended image information is supported by high-end scanners with Twain drivers that support these modes of operation. DTWAIN allows the application to retrieve this information using a series of function calls. The application can only retrieve the information during the acquisition of the image, therefore the application must process DTWAIN notifications. For these reasons, retrieving extended image information is reserved for computer languages that can process notifications, either by window handle or callback function.
Before retrieving this information, the application must verify whether the device supports Extended Image Information. The DTWAIN_IsExtImageInfoSupported function must return TRUE before proceeding.
The application must capture the DTWAIN_TN_TRANSFERDONE notification to retrieve the information. The next step is to determine what extended image information is supported by the Source. The DTWAIN_EnumExtImageInfoTypes is called to get a list of the supported types for the Source. Once the supported types have been established, the next thing to do is to initialize the extended image information structures used by the Source. The DTWAIN_InitExtImageInfo initializes the Source to retrieve extended image information. This function must be called before attempting to retrieve the image information.
The application must then call DTWAIN_GetExtImageInfoData to retrieve the extended image information that is desired.
The last function that is called is to release the memory that was used to initialize and store the extended image information. The DTWAIN_FreeExtImageInfo release all of this memory. Failure to call this function will result in a memory leak in your application.
So to summarize:
1) Check if the Source supports extended image information by calling DTWAIN_IsExtImageInfoSupported.
When the DTWAIN_TN_TRANSFERDONE notification is sent do, steps 2 - 5 2) If extended image information is supported, get a list of extended image information types that the Source supports by calling DTWAIN_EnumExtImageInfoTypes (your code can optimize this step by calling it only once and storing the values in an array)
3) Your application can now retrieve the extended information. To initiate this, the DTWAIN_InitExtImageInfo is called.
4) Retrieve the results of the query by calling DTWAIN_GetImageInfoData.
5) Call DTWAIN_FreeExtImageInfo to release the memory.
Here is a small 'C' example of how to do these steps. It is assumed that the application wants to query the barcode types found, and the Source Source has been selected and opened.
/*******************************************************************/ /* Here is the notification function that was set up with a call to DTWAIN_SetCallback */ /* i.e. DTWAIN_SetCallback( NotificationCallback, 0 ); */ /*******************************************************************/ LRESULT CALLBACK NotificationCallback(WPARAM wParam, LPARAM lParam, LONG UserInfo ) { if ( wParam == DTWAIN_TN_TRANSFERDONE ) { LONG numBarCodeTypes; LONG Count; LONG CurBarCode; DTWAIN_ARRAY AllBarCodeTypes;
/* Check if this is supported */ if ( CheckFunc( ) == 0 ) return TRUE;
/* Get the barcode information */ /* First initialize ext image info retrieval */ DTWAIN_InitExtImageInfo( Source );
/* Retrieve results for the barcode type */ if ( DTWAIN_GetExtImageInfoData( Source, DTWAIN_EI_BARCODETYPE, &AllBarCodeTypes/* Item to retrieve info */) ) { /* Now get each barcode type found */ numBarCodeTypes = DTWAIN_ArrayGetCount( AllBarCodeTypes ); for ( Count = 0; Count < numBarCodeTypes; ++Count ) { DTWAIN_ArrayGetAt( AllBarCodeTypes, Count, &CurBarCode ); /* Now CurBarCode contains a barcode type that was found */ } DTWAIN_ArrayDetroy( AllBarCodeTypes ); } /* Reclaim memory used by the image information */ DTWAIN_FreeExtImageInfo( Source ); } /***********************************************************/ /* Function to get the extended image types that are supported */ /***********************************************************/ int CheckFunc( ) { LONG NumTypes; LONG ExtImageInfoType = DTWAIN_EI_BARCODETYPE; DTWAIN_ARRAY ExtTypes; LONG PosInArray;
/* Check if ext. image info supported */ if ( DTWAIN_IsExtImageInfoSupported( Source ) == 0 ) return 0; /* Not supported, so return */
/* Check what types of information are supported */ DTWAIN_EnumExtImageInfoTypes( Source, &ExtTypes );
/* Get the number of ext image information supported */ NumTypes = DTWAIN_ArrayGetCount( ExtTypes );
/* return if NumTypes is 0 */ if ( NumTypes == 0 ) { DTWAIN_ArrayDestroy( ExtTypes ); return 0; /* No Types */ }
/* See if BARCODETYPE is one of the types by searching for it in the returned DTWAIN_ARRAY */ PosInArray = DTWAIN_ArrayFindLong( ExtTypes, DTWAIN_EI_BARCODETYPE ); if ( PosInArray != -1 ) { /* BARCODETYPE is supported */ )
/* See if BARCODECOUNT is supported */ PosInArray = DTWAIN_ArrayFindLong( ExtTypes, DTWAIN_EI_BARCODECOUNT ); if ( PosInArray != -1 ) { /* BARCODECOUNT is supported */ } /* destroy the array and return */ DTWAIN_ArrayDestroy( ExtTypes ); return 1; }
A list of image information types and their respective data types are found in the DTWAIN Extended Image Information Types. You will need to know this information to determine the data types that are used for each image information type. |