Setting Current Unit of Measure

Top 

To set the current unit of measure, the capability DTWAIN_CV_ICAPUNITS is used in conjunction with DTWAIN_SetCapValues.

 

Before setting the current unit of measure, the application must know which units of measure are supported by the Source.  The DTWAIN_GetCapValues function is called to get the supported units.

 

Below is a small function that sets the current unit of measure if the PIXEL unit is supported.

 

/* Assume that DTWAIN_SysInitialize has been called,

as well as     */

 

void SetUnitOfMeasure(DTWAIN_SOURCE Source, LONG UnitToSet)

 

         DTWAIN_ARRAY Array;  /* Will have the unit when we're done */

         LONG UnitOfMeasure; /* Returned when we're done */

         LONG Count;

 

         DTWAIN_OpenSource(Source); /* Open Source */                

 

         /* Get all of the units supported */

         DTWAIN_GetCapValues(Source,

                                         DTWAIN_CV_ICAPUNITS,

                                         DTWAIN_CAPGET,

                                         &Array);

         

         Count = DTWAIN_ArrayGetCount(Array);

 

         if ( Count <= 0 ) return; /* Error */

 

         /* Check if UnitToSet is supported */

         for (

         /* Get the returned value from the array

         DTWAIN_ArrayGetAt(Array, 0, &UnitOfMeasure);

 

         /* Return what we have found */

         return UnitOfMeasure;