EZTwain Pro 3.0 - Code Samples

Overview  Download  Licensing  Features  Code Wizard  Stories  User GuidePDF file

See also:
EZTwain Pro - Scanning from Visual Basic
EZTwain Pro - Printing Examples
EZTwain Pro - Append to a File
EZTwain Pro - Duplex Scanning

Here are some examples of complete TWAIN code for various purposes, in several of the languages generated by our Code Wizard.

In Delphi - With an Epson scanner (such as the 1660 or later), scan a square region 2" x 2", 6.5" down from the top of the page and 4" in from the left, assuming reflective media. Scan without showing the scanner's dialog, in 400 DPI RGB color. Save the scan as a high-quality JPEG (.jpg) file called "c:\sampleX.jpg"

var fileName: array [0..260] of Char;
   fileName := 'c:\sampleX.jpg';
   if TWAIN_OpenSource('EPSON TWAIN 5')=1 then
      TWAIN_SetRegion(4, 6.5, 6, 8.5);
      TWAIN_AcquireToFilename(self.Handle, fileName)
   if TWAIN_LastErrorCode()<>0 then
      TWAIN_ReportLastError('Unable to scan.')

In C#, scan a single 16-bit/pixel grayscale image at 300 DPI without showing the scanner's dialog, and save to TIFF:

string fileName;
fileName = "c:\\baseline.tif";
if (EZTwain.OpenDefaultSource()==1) {
   // Not guaranteed to work, check return = 1:
   // Not guaranteed to work, check return = 1:
   EZTwain.AcquireToFilename(this.Handle, fileName);
if (EZTwain.LastErrorCode()!=0) {
   EZTwain.ReportLastError("Unable to scan.");