Example 12: Retrieving Extended Image Information

Top  Previous  Next

Example:  Retrieve device Extended Image Information.  To retrieve the extended image information, the device must support extended image information, and the information can only be retrieved when the OnTransferDone notification is sent.  To do this easily, a listener is created to capture OnTransferDone.

 

#include "cdtwain.h"

#include <string>

#include <iostream>

#include <algorithm>

 

using namespace DTWAIN;

using namespace std;

 

class MyExtendedImageInfoListener : public DTwainListener

{

public:

     // This function is called when a transfer is done

     LRESULT OnTransferDone( DTwainSource& Source, LONG UserParam )

     {

        // Check if extended image info is supported

        if ( Source.IsExtImageInfoSupported( ) )

        {

           // Create extended image info object

           DTwainExtendedImageInfo EI( Source );

         

           // Get the extended image information types supported by the Source

           // i.e. bar-code info, inprinter info, etc.

          DTwainLongArray EITypes;

           EI.EnumTypes( EITypes);

 

           // We will like to check if the barcode text is supported, and

           // Get the image information

         

          // Use the std::find algorithm

          if ( std::find( EITypes.begin( ), EITypes.end( ), DTwainExtendedImageInfo::EI_BARCODETEXT ) !=

                 EITypes.end( ) )

          {

              // bar code text exists.  Get the text        

              DTwainStringArray BarcodeText;

              EI.GetData(BarcodeText, DTwainExtendedImageInfo::EI_BARCODETEXT );

             

              // display the text

              int nText = BarcodeText.size( );

              for ( int i = 0; i < nText; ++i )

                   cout << BarcodeText[i] << endl;

           }

        }

        return 1;

     }

};

 

int main( )

{

  DTwainInterface TI;  // Initialize DTWAIN

   DTwainSource Source = DTwainSource::Select( );

   if ( !Source.IsValid( ) )

       return 0;

   

    DTwainAcquirer Acq( Source );

 

    // Create a listener

    MyExtendedImageInfoListener EIListener;

 

    // Add it to the list of listeners in the DTwainAcquirer object

    Acq.AddListener( &EIListener );

 

    // Go

    Acq.Acquire("DTWAIN.BMP");      

}