Example 8: Acquire using Twain driver file support

Top  Previous  Next

Example:  Acquiring using the Twain drivers file transfer support (not DTWAIN file support).  Twain driver must support BMP transfer for this example to work.

 

#include "cdtwain.h"  // CDTwain

using namespace DTWAIN;

 

int main( )

{

  // Initialize DTWAIN - return if initialization does not work

  DTwainInterface TI;

  if ( !TI.IsValid( ) )

      return 0;

 

  // Select a source

  DTwainSource Source = DTwainSource::Select( );

  if ( !Source.IsValid( ) )

     return 0;

 

  // Create an acquire object, attach the source

  DTwainAcquirer Acq( Source );

 

  // Create a source mode file transfer helper object, and attach Source to the object,

  DTwainSourceFileTransfer FT(Source);

 

  // check if BMP file transfers are supported by the Source

  if ( !FT.IsSupported( FILETYPE_SOURCE_BMP ) )

       return 0;  // not supported

 

  // Set the transfer type

  FT.SetTransferType( FILETYPE_SOURCE_BMP );

 

  // Go.

  Acq.Acquire( FT, "FILE.BMP"  );  

} // If acquisition completed, a file called FILE.BMP contains the raw image data that was transferred.