Retrieving Image Information before Acquiring

Top  Previous  Next

For many reasons, an application may desire to check the size, bit-depth, etc. of an image before it is acquired.  To do this the function to call is DTWAIN_GetImageInfo.  Note that this function is only relevant if your application is processing DTWAIN notifications since the TWAIN driver can only know the image dimensions and other information during the acquisition process.

 

To call DTWAIN_GetImageInfo correctly, your application should process the DTWAIN_TN_TRANSFERREADY and DTWAIN_TN_PROCESSEDDIB notifications and call DTWAIN_GetImageInfo when these notifications are sent.  For most TWAIN devices, the DTWAIN_TN_TRANSFERREADY notification is all that's necessary to retrieve the image information.  This allows your application to inspect the dimensions, bit-depth, etc. of the image, and accept or reject the image transfer based on the parameters.  To stop the transfer of an image, your application must return a 0 after processing the DTWAIN_TN_TRANSFERREADY notification.  See DTWAIN Notifications for more information on the DTWAIN_TN_TRANSFERREADY notifications.

 

There are some TWAIN drivers that do not report the image information correctly when the transfer begins.  For these devices, the image information is valid after the transfer has taken place.  Usually, these devices are hand-held scanners, or devices that determine the image dimensions after the acquisition has taken place (some scanners use a mode where the scanner scans the image, and then from the scanned image, determines the size of the image by the size of the paper in the scanner).  For these devices, your application should process the DTWAIN_PROCESSEDDIB or DTWAIN_TRANSFERDONE notification.  You can tell if the device is one that determines the image size after the acquisition has been done by calling DTWAIN_GetImageInfo during DTWAIN_TRANSFERREADY processing and checking for a -1 value for the width and height of the image.  A value of -1 means that the call to DTWAIN_GetImageInfo couldn't retrieve the image information.