Take the following steps to start a project and to add some code that acquires the images using Fast Twain:
Start Visual Studio .NET.
Choose File->New->Project… from the menu.
In the New Project dialog box, choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and choose "Windows Application" in the Templates List.
Type the project name as "UsingFastTwainFeature" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK.
In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32" folder and select the following DLLs:
Click the Select button and then press the OK button to add the above DLLs to the application.
| Text | Name | Checked |
| Native | radioNative | False |
| Memory | radioMemory | False |
| Text | Name |
|---|---|
| Fast Acquire | buttonFastAcquire |
| Name | Name |
|---|---|
| Use Buffer Size | checkBoxUseBufferSize |
| Property | Value |
|---|---|
| Name | textBufferSize |
| Name | textFileName |
Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code) and add the following lines at the beginning of the file:
Imports LeadtoolsImports Leadtools.TwainImports Leadtools.CodecsImports Leadtools.WinForms
using Leadtools;using Leadtools.Twain;using Leadtools.Codecs;using Leadtools.WinForms;
Declare the following private variable:
Private WithEvents twnSession As TwainSession
private TwainSession twnSession;
Add an event handler to the Form1 Load event and code it as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadtextFileName.Text = "c:\twain_test.tif"textBufferSize.Text = "2048"Try' Unlock Document support.' Note that this is a sample key, which will not work in your toolkit.Dim MY_LICENSE_FILE As String = "d:\temp\TestLic.lic"Dim MY_DEVELOPER_KEY As String = "xyz123abc"RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY)twnSession = new TwainSessiontwnSession.Startup(Me.Handle, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.InitializeMultithreaded)Catch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd Sub
private void Form1_Load(object sender, System.EventArgs e){textFileName.Text = @"c:\twain_test.tif";textBufferSize.Text = "2048";try{// Unlock Document support.// Note that this is a sample key, which will not work in your toolkit.string MY_LICENSE_FILE = "d:\\temp\\TestLic.lic";string MY_DEVELOPER_KEY = "xyz123abc";RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY);twnSession = new TwainSession();twnSession.Startup(this.Handle, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.InitializeMultithreaded);}catch (Exception ex){MessageBox.Show(this, ex.Message);}}
Add an event handler to the Form1 Closing event and code it as follows:
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosingTrytwnSession.Shutdown()Catch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd Sub
private void Form1_FormClosing(object sender, FormClosingEventArgs e){try{twnSession.Shutdown();}catch (Exception ex){MessageBox.Show(this, ex.Message);}}
Add an event handler to the buttonFastAcquire Click event and code it as follows:
Private Sub buttonFastAcquire_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonFastAcquire.ClickDim transferMode As TwainTransferModeDim transferFormat As RasterImageFormatIf radioMemory.Checked ThentransferMode = TwainTransferMode.BuffertransferFormat = RasterImageFormat.CcittGroup4ElsetransferMode = TwainTransferMode.NativetransferFormat = RasterImageFormat.TifEnd IfTrytwnSession.AcquireFast(textFileName.Text, _TwainFastUserInterfaceFlags.Show Or TwainFastUserInterfaceFlags.UseThread, _transferMode, _transferFormat, _1, _True, _Convert.ToInt32(textBufferSize.Text), _checkBoxUseBufferSize.Checked)Catch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd Sub
private void buttonFastAcquire_Click(object sender, System.EventArgs e){TwainTransferMode transferMode;RasterImageFormat transferFormat;if (radioMemory.Checked){transferMode = TwainTransferMode.Buffer;transferFormat = RasterImageFormat.CcittGroup4;}else{transferMode = TwainTransferMode.Native;transferFormat = RasterImageFormat.Tif;}try{twnSession.AcquireFast(textFileName.Text,TwainFastUserInterfaceFlags.Show | TwainFastUserInterfaceFlags.UseThread,transferMode,transferFormat,1,true,Convert.ToInt32(textBufferSize.Text),checkBoxUseBufferSize.Checked);}catch (Exception ex){MessageBox.Show(ex.Message);}}
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
