EZTwain
Pro 3.0 - Code Samples
Overview Download How To Buy Features Code Samples User Guide Stories
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;
begin
fileName := 'c:\sampleX.jpg';
TWAIN_SetHideUI(1);
TWAIN_SetJpegQuality(90);
if TWAIN_OpenSource('EPSON TWAIN 5')=1 then
begin
TWAIN_SetPixelType(2);
TWAIN_SetResolution(400);
TWAIN_SetXferCount(1);
TWAIN_SetRegion(4, 6.5, 6,
8.5);
TWAIN_AcquireToFilename(self.Handle,
fileName)
end;
if TWAIN_LastErrorCode()<>0 then
TWAIN_ReportLastError('Unable
to scan.')
end
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";
EZTwain.LogFile(1);
EZTwain.SetHideUI(1);
EZTwain.SetFileAppendFlag(0);
if (EZTwain.OpenDefaultSource()==1) {
EZTwain.SetXferMech(2);
// Not guaranteed to work, check return = 1:
EZTwain.SetPixelType(1);
// Not guaranteed to work, check return = 1:
EZTwain.SetBitDepth(16);
EZTwain.SetResolution(300);
EZTwain.SetXferCount(1);
EZTwain.AcquireToFilename(this.Handle, fileName);
}
if (EZTwain.LastErrorCode()!=0) {
EZTwain.ReportLastError("Unable to scan.");
}
|