Example 3: Acquire to a multi-page TIFF

Top  Previous  Next

Example :  Start DTWAIN, Select the default Source, Acquire to a multi-page TIFF File (Group 4 Tiff) called MYTIFF.TIF

 

#include "cdtwain.h"

using namespace DTWAIN;

 

int main( )

{

  // Initialize DTWAIN - return if initialization does not work

  DTwainInterface TI;

  if ( !TI.IsValid( ) )

      return 0;

 

  // Declare a Source and assign the default TWAIN source to it

  DTwainSource Source = DTwainSource::SelectDefault( );

  if ( !Source.IsValid( ) )

     return 0;

 

  // Declare an acquisition object, and attach the source to it

  DTwainAcquirer Acq(Source);

 

  // Set maximum pages to acquire (all the pages)

  Acq.SetMaxPages( DTWAIN_ACQUIREALL );

 

  // Make sure that black/white is pixel type

  Acq.SetColorType(COLORTYPE_BW);

 

  // Start acquisition process

  Acq.Acquire( "MYTIFF.TIF", FILETYPE_TIFFG4 );        

}

 

Here is an alternate version using function chaining and named parameters to initialize the DTwainAcquirer object:

 

#include "cdtwain.h"

using namespace DTWAIN;

 

int main( )

{

  // Initialize DTWAIN - return if initialization does not work

  DTwainInterface TI;

  if ( !TI.IsValid( ) )

      return 0;

 

  // Declare a Source and assign the default TWAIN source to it

  DTwainSource Source = DTwainSource::SelectDefault( );

  if ( !Source.IsValid( ) )

     return 0;

 

  // Declare an acquisition object, attach the source to it, set parameters, and acquire

  DTwainAcquirer(Source)   // Set the source

       .SetMaxPages( DTWAIN_ACQUIREALL )  // Set maximum pages to acquire

       .SetColorType(COLORTYPE_BW)  // Set color type to black/white

       .Acquire( "MYTIFF.TIF", FILETYPE_TIFFG4 );

}

 

Note that the call to Acquire( ) must be the last call in this function chain.