Example 6: Get all Brightness values

Top  Previous  Next

Example: Get all the brightness values of the Twain device (if device supports brightness setting)

 

#include "cdtwain.h"

#include <iostream>

 

using namespace DTWAIN;

using namespace std; // for <iostream>

 

int main( )

{

  // Initialize DTWAIN - return if initialization does not work

  DTwainInterface TI;

  if ( !TI.IsValid( ) )

      return 0;

 

  // Declare a Source and allow user to choose TWAIN source

  DTwainSource Source = DTwainSource::Select( );

  if ( !Source.IsValid( ) )

     return 0;

 

  // Only do this if the number of brightness values > 0

  // Get the brightness values

  DTwainDoubleArray BrightnessValues;

  Source.EnumBrightnessValues( BrightnessValues, false );

 

  if (  ! BrightnessValues.empty( ) )

  {

         // The values may be in the form of a range, so let's do some work and expand the

         // range into discrete values.  We could have expanded the

         // values already when EnumBrightnessValues was called by supplying another argument,

         // but this code is done to illustrate the CopyArrayToRange function.

         if ( Source.IsCapContainerRange( DTWAIN_CV_ICAPBRIGHTNESS ) )

         {

             // Create a temporary range from the returned BrightnessValues array,

             // and expand the range back into the BrightnessValues array

            DTwainDoubleRange( ).CopyArrayToRange( BrightnessValues ).Expand( BrightnessValues );

         }

         // Now output the values (could be a lot!)

         DTwainDoubleArray::iterator start = BrightnessValues.begin( );

         DTwainDoubleArray::iterator stop = BrightnessValues.end( );

         while ( start != stop )

         {

             cout << *start << endl;

             ++start;

         }

     }              

     else

     {

        cout << "Your TWAIN driver does not support brightness setting" << endl;

     }        

}