Imports Leadtools
Imports Leadtools.Twain
Public Sub twain_FastConfiguration(ByVal sender As Object, ByVal e As TwainFastConfigurationEventArgs)
' ... set your code here
e.Stop = False
End Sub
Public Sub FindFastConfigurationExample(ByVal parent As IWin32Window)
Dim session As TwainSession = New TwainSession()
session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None)
session.EnableFastConfigurationEvent = True
AddHandler session.FastConfiguration, AddressOf twain_FastConfiguration
Dim twFastConfig As RasterCollection(Of TwainFastConfiguration) = Nothing
Dim tempFastConfig As TwainFastConfiguration = New TwainFastConfiguration()
tempFastConfig = TwainFastConfiguration.Default
tempFastConfig.TransferMechanism = TwainTransferMode.File
tempFastConfig.ImageFormat = Leadtools.RasterImageFormat.Bmp
tempFastConfig.BitsPerPixel = 1
twFastConfig.Add(tempFastConfig)
tempFastConfig.TransferMechanism = TwainTransferMode.File
tempFastConfig.ImageFormat = Leadtools.RasterImageFormat.Tif
tempFastConfig.BitsPerPixel = 1
twFastConfig.Add(tempFastConfig)
Dim fastConfigRes As TwainFindFastConfigurationResult
Try
fastConfigRes = session.FindFastConfiguration(Path.Combine(LEAD_VARS.ImagesDir, ""), TwainFastUserInterfaceFlags.Show, 0, 1, twFastConfig)
Dim msg As String
MessageBox.Show("FindFastConfig method was successful")
msg = String.Format("Result Scan Configs count = {0}", fastConfigRes.Tested.Count)
MessageBox.Show(msg)
msg = String.Format("Transfer Mode = {0}" & Constants.vbLf & "File Format = {1}" & Constants.vbLf & "Buffer Size = {2}" & Constants.vbLf & "Required Time = {3}" & Constants.vbLf, fastConfigRes.Tested(0).TransferMechanism, fastConfigRes.Tested(0).ImageFormat, fastConfigRes.Tested(0).BufferSize, fastConfigRes.Tested(0).RequiredTime)
MessageBox.Show(msg, "Tested Scan Configurations...")
msg = String.Format("Transfer Mode = {0}" & Constants.vbLf & "File Format = {1}" & Constants.vbLf & "Buffer Size = {2}" & Constants.vbLf & "Required Time = {3}" & Constants.vbLf, fastConfigRes.Best.TransferMechanism, fastConfigRes.Best.ImageFormat, fastConfigRes.Best.BufferSize, fastConfigRes.Best.RequiredTime)
MessageBox.Show(msg, "Best Scan Configurations...")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
session.Shutdown()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Twain;
public void twain_FastConfiguration(object sender, TwainFastConfigurationEventArgs e)
{
// ... set your code here
e.Stop = false;
}
public void FindFastConfigurationExample(IWin32Window parent)
{
TwainSession session = new TwainSession();
session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None);
session.EnableFastConfigurationEvent = true;
session.FastConfiguration += new EventHandler<TwainFastConfigurationEventArgs>(twain_FastConfiguration);
RasterCollection<TwainFastConfiguration> twFastConfig = null;
TwainFastConfiguration tempFastConfig = new TwainFastConfiguration();
tempFastConfig = TwainFastConfiguration.Default;
tempFastConfig.TransferMechanism = TwainTransferMode.File;
tempFastConfig.ImageFormat = Leadtools.RasterImageFormat.Bmp;
tempFastConfig.BitsPerPixel = 1;
twFastConfig.Add(tempFastConfig);
tempFastConfig.TransferMechanism = TwainTransferMode.File;
tempFastConfig.ImageFormat = Leadtools.RasterImageFormat.Tif;
tempFastConfig.BitsPerPixel = 1;
twFastConfig.Add(tempFastConfig);
TwainFindFastConfigurationResult fastConfigRes;
try
{
fastConfigRes = session.FindFastConfiguration(Path.Combine(LEAD_VARS.ImagesDir, ""), TwainFastUserInterfaceFlags.Show, 0, 1, twFastConfig);
string msg;
MessageBox.Show("FindFastConfig method was successful");
msg = String.Format("Result Scan Configs count = {0}", fastConfigRes.Tested.Count);
MessageBox.Show(msg);
msg = String.Format("Transfer Mode = {0}\nFile Format = {1}\nBuffer Size = {2}\nRequired Time = {3}\n",
fastConfigRes.Tested[0].TransferMechanism,
fastConfigRes.Tested[0].ImageFormat,
fastConfigRes.Tested[0].BufferSize,
fastConfigRes.Tested[0].RequiredTime);
MessageBox.Show(msg, "Tested Scan Configurations...");
msg = String.Format("Transfer Mode = {0}\nFile Format = {1}\nBuffer Size = {2}\nRequired Time = {3}\n",
fastConfigRes.Best.TransferMechanism,
fastConfigRes.Best.ImageFormat,
fastConfigRes.Best.BufferSize,
fastConfigRes.Best.RequiredTime);
MessageBox.Show(msg, "Best Scan Configurations...");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
session.Shutdown();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}