ImageGear for C and C++ on Windows v19.4 - Updated
Write a Simple Scanning Application
User Guide > How to Work with... > Common Operations > Scanning > ISIS Scanning > Write a Simple Scanning Application

There are several different ways to accomplish the task of scanning a page and saving it in a file. This section shows one of those ways, not necessarily the easiest, but a good illustration of all of the required steps. The following steps will scan a page using your scanner's default settings (usually binary, 300 dpi, no dither, letter paper size) and put the resulting data into a TIFF file.

If your scanner outputs compressed data, the TIFF file will contain data with the same compression. No attempt is made to compress or decompress the image.

The sample code utilizes the SPEW or Image Spewer driver which is a test scanner driver included in PixTools/Scan. The SPEW driver can be configured to output sample image data and to simulate both basic and advanced scanning functions for application testing.

  1. Load and initialize the scanner driver. The first parameter of the IG_ISIS_drv_load function is reserved and must be zero.
     
    Copy Code
    IG_ISIS_drv_load(0, "SPEW", &hScan, 0);
    IG_ISIS_drv_init(hScan, 0, 0);
    

    The above IG_ISIS_drv_load function loads the Image Spewer driver. If you prefer, substitute the filename (without extension) of your scanner driver within the quotes. The handle to the driver (hScan) is a HISISDRV.

  2. Load and initialize the file writing driver:
     
    Copy Code
    IG_ISIS_drv_load(0, "PIXFPACK", &hFileWriter, 0);
    IG_ISIS_drv_init(hFileWriter, 0, 0);
    

    PIXFPACK is Pixel's universal file writing driver - it can write any supported file format.

  3. Link the drivers into an ISIS pipe:
     
    Copy Code
    IG_ISIS_drv_link(hScan, hFileWriter);
    
  4. Set tags on the pipe to specify the filename, file type, and how to write the file:
     
    Copy Code
    IG_ISIS_tag_set_ascii(hFileWriter, IG_ISIS_TAG_OUTPUTNAME, (char FAR *)"TEST.TIF");
    IG_ISIS_tag_set_long(hFileWriter, IG_ISIS_TAG_FILETYPE, 0, IG_ISIS_FILETYPE_TIFF);
    

    Each IG_ISIS_tag_set... call sets the value of one tag. IG_ISIS_TAG_OUTPUTNAME is set to the ASCII string "TEST.TIF." The remaining tags are type long values with defined constant names. IG_ISIS_TAG_FILETYPE is set to IG_ISIS_FILETYPE_TIFF.

    Once the ISIS drivers are linked into a pipe, the tags can be set on any driver, provided that their meanings are not ambiguous. In this example, each of these tags could have been set on hScan rather than on hFileWriter. This characteristic will become more important when you only have a handle to a pipe, rather than individual drivers.

    Many application developers mistakenly try to use IG_ISIS_tag_set_long to set the filename. It is important to use the correct tag set function for the various data types. In this case, be sure to use IG_ISIS_tag_set_ascii to set the filename.

  5. Invoke the pipe:
     
    Copy Code
    IG_ISIS_run_zone(hScan, Buffer, BUFSIZE);
    

    This call tells the head driver to run a zone, which means to scan a page and send the resulting data down the pipe. The other drivers in the pipe respond automatically, performing whatever function they are designed to perform. In this case, PIXFPACK writes the image data into a TIFF file named TEST.TIF.

  6. Unlink and unload the drivers when you are done with them:
     
    Copy Code
    IG_ISIS_drv_link(hScan, 0);
    IG_ISIS_drv_unload(hFileWriter);
    IG_ISIS_drv_unload(hScan);
    

    To unlink the scanner driver, link it with nothing (zero). Note that the drivers are unlinked and unloaded in reverse order of loading.

Example:

Here is the complete code to scan a page to a file:

 
Copy Code
#include <windows.h>

#include "gear.h"
#include "i_ISIS.h"

void ScanPageToFile( )
{
    BYTE buffer[8192];
    HISISDRV hScan = 0;
    HISISDRV hFileWriter = 0;

    // Load and initialize the scanner driver.
    IG_ISIS_drv_load(0, "SPEW", &hScan, 0);
    IG_ISIS_drv_init(hScan, 0, 0);

    // Load and initialize the file writing driver.
    IG_ISIS_drv_load(0, "PIXFPACK", &hFileWriter, 0);
    IG_ISIS_drv_init(hFileWriter, 0, 0);

    // Link the scanner driver to the file writing driver.
    IG_ISIS_drv_link(hScan, hFileWriter);

    // Set tags to correctly write the file
    IG_ISIS_tag_set_ascii(hFileWriter, IG_ISIS_TAG_OUTPUTNAME, (char FAR *)"Test.tif");
    IG_ISIS_tag_set_long(hFileWriter, IG_ISIS_TAG_FILETYPE, 0, IG_ISIS_FILETYPE_TIFF);

    // Invoke the pipe and scan the page.
    IG_ISIS_run_zone(hScan, buffer, sizeof(buffer));

    // Unlink and unload the drivers.
    IG_ISIS_drv_link(hScan, 0);
    IG_ISIS_drv_unload(hFileWriter);
    IG_ISIS_drv_unload(hScan);
}