Victor Image Processing Library How-to Tips

Scan and Print a Document

This is a straight forward use of the scanner and print functions. The procedure is to scan the document into an image buffer, then print it. The Victor Library supports scanning with TWAIN-compliant scanners.

This example uses a scan resolution of 200 dpi, but this can be changed. Also, the horizontal and vertical resolutions do not have to be set to the same value, use different values if necessary.

To scan and print, the steps are:

This example sets all parameters and automatically scans and saves. To invoke the user interface either set showUI to TRUE or use the TWscanimage function (commented out).

This is a stand alone function that will initialize the scanner each time it is called. If your app will scan more than one page then for faster scanning use

at the top of the app and TWclose at the bottom. The open/close functions are not necessary (all of the TWscanimagexxxxxx functions perform open/close as needed) but can really speed up an app that scans multiple images.

Scan and Print - the Source Code

Requires Victor Image Processing Library v 5.x or higher.
Add the Victor import libraries vic32ms.lib and vctw32ms.lib (or vic32bc.lib and vctw32bc.lib for non-Microsoft compilers) to your project.
// Scan and print a document 
int scanTW_and_print(char far *fname)
   imgdes image1;
   int rcode;
   int compression = 0; 
   int showUI = FALSE;  // Hide user interface
   TWAIN_CAP_DATA pixeltype;
   TWAIN_CAP_DATA brightness;
   TWAIN_CAP_DATA contrast;
   TWAIN_CAP_DATA resolution;
   TWAIN_CAP_DATA resunits;
   HWND hwnd;
   RECT scanrect;
   hwnd = GetActiveWindow();
   if(rcode = TWdetecttwain(hwnd) != NO_ERROR)
      return (rcode);
   resunits.oneValue.val = TWUN_INCHES;
   resunits.conType = TWON_ONEVALUE;
   resolution.oneValue.val = 200; // 200 dpi
   resolution.conType = TWON_ONEVALUE;
             // For grayscale use: pixeltype.oneValue.val = TWPT_GRAY; 
   pixeltype.oneValue.val = TWPT_BW;   1-bit b/w
   pixeltype.conType = TWON_ONEVALUE;
   brightness.oneValue.val = 0; // Range is usually -1000 to 1000
   brightness.conType = TWON_ONEVALUE;
   contrast.oneValue.val = 0; // Range is usually -1000 to 1000
   contrast.conType = TWON_ONEVALUE;
            // We're setting parameters here, but the scanner may choose to ignore our settings
   TWsetmeasureunit(hwnd, &resunits);    // Set the device units
   TWsetxresolution(hwnd, &resolution);  // Set the device resolution
   TWsetyresolution(hwnd, &resolution);  // Set the device resolution
   TWsetbrightness(hwnd, &brightness);   // Set brightness
   TWsetcontrast(hwnd, &contrast);       // Set contrast
   TWsetpixeltype(hwnd, &pixeltype);     // Set the pixel type
   scanrect.left = 250;      // Scan bed coordinates in 1000th inch = 500;       // 1/4-inch side, 1/2-inch top margins 
   scanrect.right = 8000 + 250;    // 8 inches wide
   scanrect.bottom = 10500 + 500;  // 10 inches high
            //   rcode = TWscanimage(hwnd, &image1); // For TWAIN user interface
   rcode = TWscanimageex(hwnd, &image1, &scanrect, showUI); // No user interface
   if(rcode == NO_ERROR) { // Successful scan, now print the image
      HDC hdcprn;
      hdcprn = GetPrinterDC();  // Function defined below
      if (hdcprn == NULL)
         rcode = PRT_ERR;
      else {
         RECT prtrect;
         prtrect.left =   0; =    0;
         prtrect.right =  7999;
         prtrect.bottom = 10499;
            // Simpliest form of the print function, no display progress dlg
         rcode = printimage(hwnd, hdcprn, 0, &image1, &prtrect, 0, 0);
// Get a Device Context for the printer
HDC GetPrinterDC(void)
   char szPrinter[PRINTER_BUFFER_SIZE];
   char *szDevice, *szDriver, *szOutput;
   GetProfileString("windows", "device", "", szPrinter, sizeof(szPrinter));
   if((szDevice = strtok(szPrinter, ",")) != 0 &&
      (szDriver = strtok(0, ",")) != 0 &&
      (szOutput = strtok(0, ",")) != 0)
      return(CreateDC(szDriver, szDevice, szOutput, 0));
Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code

Copyright © 2000 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.