| Home | Download | Register | Testimonials | Support |
|
||||||||||
|
VintaSoftTwain ActiveX Control For which purposes can I use VintaSoftTwain ActiveX control? The ActiveX can be used for controlling an work of scanners, web cameras and any other devices which support TWAIN standard. In which programming languages can I use this ActiveX control? With Single Developer license or Site license you can use ActiveX in: With Server license you can use ActiveX in: What restrictions does the unregistered version have? Unregistered version has the following restrictions: All these restrictions are removed in registered version. I have problems. What should I do? The information on most of questions can be found in the documentation or in this FAQ. Write to our support team to get more help. Can I re-distribute this ActiveX control with my application without royalties? Yes, this control is royalty free. You pay only for registration one time. Single Developer license has limitation in re-distribution. Please see license agreement. What files do I need to include in the setup package of my program? You must include only one file: vstwain.dll. After installation of your program onto clean computer, please register the ActiveX control by regsvr32.exe program (regsvr32.exe vstwain.dll). I have created the program in Visual Studio .NET. What must I do for correct installation of my program on client computer? Before distribution of your program:
When you distribute your program you need:
I have an error message when I try to register the program in Windows 98. What should I do? This is the problem with dependencies. ActiveX has the following dependencies: Please install the Visual C++ run time files on computer to solve this problem. This setup package can be downloaded from this link: http://download.microsoft.com/download/vc60pro/update/1/w9xnt4/en-us/vc6redistsetup_enu.exe I have created the program in Delphi. The program works correctly when user is logged as administrator, but when user is logged as guest he get following message at start of the program "Exception EOleSysError in module...". How can I solve this problem? First of all it's necessary to register ActiveX in the system by register32.exe program. This operation must be made with administrator rights. Further it's necessary to add following code to your program:
program Simple;
uses
Forms,
Windows, Registry, Dialogs, ActiveX,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
function IsVSTwainRegistered : Boolean;
var Reg:TRegistry;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_CLASSES_ROOT;
Result:=Reg.OpenKey('CLSID\{1169E0CD-9E76-11D7-B1D8-FB63945DE96D}',False);
if Result then Reg.CloseKey;
finally
Reg.Free;
end;
end;
begin
if not IsVSTwainRegistered() then
begin
ShowMessage('VintaSoftTwain ActiveX is not registered!');
Exit;
end;
OleInitialize(nil);
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
OleUninitialize;
end.
This code allows to check that the program is registered in the system and allows to run your program with guest rights.How can I add a VintaSoftTwain object to a form of my VB.NET project? You should do the following steps to add the object to your form:
I want to use ActiveX in Delphi 2005 and BDS 2006, but the forms designer does not accept ActiveX controls to a form. It gives error message "Failed to add a reference to the ActiveX type library. Ensure that it is properly registered. ...". How can I solve this problem? Borland Delphi 8.0 (2005) and Borland C# Builder 1.0 have bug and they accept ActiveX controls only if US locale is used. Other locales are ignored. Here are steps which help to solve this problem: How can I dynamically add VintaSoftTwain object in my VB project? You must do following steps: 1. Go to menu "Project -> References". 2. In opened window you need to add reference to "VintaSoftTwain ActiveX Control" object. 3. Next you need add following code to your project:
Option Explicit
Dim WithEvents VSTwain1 As VSTWAINLib.VintaSoftTwain
Private Sub StartScan_Click()
Set VSTwain1 = New VSTWAINLib.VintaSoftTwain
With VSTwain1
.StartDevice
If .SelectSource = 1 Then
.showUI = True
.Acquire
End If
End With
End Sub
Private Sub VSTwain1_PostScan(ByVal flag As Long)
If flag <> 0 Then
If VSTwain1.errorCode <> 0 Then
MsgBox VSTwain1.errorString
End If
Else
Set Image1.Picture = VSTwain1.GetCurrentImage
VSTwain1.tiffCompression = 10
VSTwain1.SaveImage 0, "c:\test.tif"
End If
End Sub
I try to use VintaSoftTwain ActiveX in Windows 2003 Server, but I always have error: "Error at loading the TWAIN_32.DLL". How can I solve this problem? Your version of Windows 2003 Server has bug in configuration: GetWindowsDirectory function returns incorrect path to Windows directory, "C:\Documents and Settings\User\Windows\" instead of "C:\Windows\". Please read this article which helps you to solve the problem: http://support.microsoft.com/kb/832048. I cannot add VintaSoftTwain ActiveX to a form of my application in VS .NET 2005. How can I solve this problem? You must add reference to the "stdole" library to your project before inserting the VintaSoftTwain object to your form. Here are necessary steps:
After these steps you can add the VintaSoftTwain object to your form without any problems. How can I sign my copy of ActiveX for using it on my web page? VintaSoftTwain ActiveX is signed by certificate from Thawte. Please contact us, if you want to sign your copy of VintaSoftTwain ActiveX by your own certificate. What steps should I do for adding the ActiveX to my web project? You need to do following steps: 1. Add vstwain.dll file onto server. 2. In your HTML file you must change the code base of an OBJECT object.
// In example:
<OBJECT ID="VSTwain1" WIDTH=1 HEIGHT=1
CLASSID="CLSID:1169E0CD-9E76-11D7-B1D8-FB63945DE96D"
CODEBASE="">
</OBJECT>
// In your code:
<OBJECT ID="VSTwain1" WIDTH=1 HEIGHT=1
CLASSID="CLSID:1169E0CD-9E76-11D7-B1D8-FB63945DE96D"
CODEBASE="http://www.your-server.com/activex/vstwain.dll#version=4,0,0,3">
</OBJECT>
In this case you do not need to install ActiveX on all computers in
your organization. When user will open an twain page he will
automatically install ActiveX onto the computer.Also you can create CAB file if you want (CODEBASE="http://www.your-server.com/activex/vstwain.cab"). How can I upload acquired image to the Web server? HTTP protocol not allows to save files directly onto Web (HTTP) server. For this purpose you must use specialized web-script. This script must be placed onto the server and only via this script you can upload files to the server. You can find many scripts in internet or use one of the following scripts: ASP script, Perl script. For uploading image onto the server via script it's necessary to know which fields the script contain. ASP script contain following fields: And you should use the following code for uploading images via this script:
if VSTwain1.SetHttpServerParams("http://www.your-server.com/clsUploadTest.asp",
"http://www.your-server.com/clsUploadTest.asp", 4) = 0 then
MsgBox VSTwain1.errorString
else
VSTwain1.SetHttpFormField "Demo", "Demo string"
VSTwain1.SetHttpFormField "cmdSubmit", "SUBMIT"
if VSTwain1.SaveImageToHttp(0, "txtFile", "demo.jpg") = 0 then
MsgBox VSTwain1.errorString
else
Timer.Interval = 10
end if
end if
Perl script contain following fields:
And you should use the following code for uploading images via this script:
if VSTwain1.SetHttpServerParams("http://www.your-server.com/cgi/upload.cgi",
"http://www.your-server.com/upload.html", 4) = 0 then
MsgBox VSTwain1.errorString
else
VSTwain1.SetHttpFormField "login", "guest"
VSTwain1.SetHttpFormField "pass", "guest"
if VSTwain1.SaveImageToHttp(0, "file", "demo.jpg") = 0 then
MsgBox VSTwain1.errorString
else
Timer.Interval = 10
end if
end if
Please see our examples.I try to select device with the sourceIndex property in Internet Explorer but I get an error. Why? Each object of web page in Internet Explorer has a sourceIndex property. This is a read-only property. You must use the following code to work with a sourceIndex property of a VSTwain object in JavaScript or VBScript: VSTwain1.StartDevice() VSTwain1.object.sourceIndex = 1 ' second device VSTwain1.Acquire() How can I acquire black-white images? Here is a sample of code for acquiring only black-white images:
Private Sub StartScan()
VSTwain1.StartDevice()
If VSTwain1.SelectSource() = 1 Then
VSTwain1.OpenDataSource()
VSTwain1.pixelType = 0 ' 0 - BW images, 1 - gray images , 2 - RGB images
VSTwain1.Acquire()
End If
End Sub
The programming language what I use do not support work with arrays. How can I solve this problem? If you want to get an array of values from GetPageSizes, GetPixelTypes, GetResolutions, GetUnitsOfMeasure methods, but your programming language not support work with arrays, you can use following method:
' This example shows how to get supported pixel types
VSTwain1.StartDevice()
VSTwain1.OpenDataSource()
bSupportBW = 0
VSTwain1.pixelType = 0 ' black-white (1 bit per pixel)
if VSTwain1.errorCode = 0 then ' black-white images is supported by device
bSupportBW = 1
end if
bSupportGray = 0
VSTwain1.pixelType = 1 ' gray (8 bit per pixel)
if VSTwain1.errorCode = 0 then ' gray images is supported by device
bSupportGray = 1
end if
bSupportRGB = 0
VSTwain1.pixelType = 2 ' RGB (24 bit per pixel)
if VSTwain1.errorCode = 0 then ' RGB images is supported by device
bSupportRGB = 1
end if
...................
How can I work with ADF without User Interface? Here is a sample of code to drive a scanner with an ADF without the Data Source user interface:
Private Sub StartScan()
VSTwain1.StartDevice()
If VSTwain1.SelectSource() = 1 Then ' user selected the device
VSTwain1.showUI = False ' disable UI
VSTwain1.disableAfterAcquire = True
VSTwain1.maxImages = 1
VSTwain1.autoCleanBuffer = True
VSTwain1.tiffMultiPage = True ' multi page TIFF file
VSTwain1.tiffCompression = 10 ' auto detect of best compression algorithm
If VSTwain1.OpenDataSource() = 1 Then
VSTwain1.unitOfMeasure = 0 ' inches
VSTwain1.pixelType = 0 ' black-white image
VSTwain1.resolution = 200 ' 200 dpi
If VSTwain1.feederPresent = 1 Then
VSTwain1.feederEnabled = True
If VSTwain1.duplex <> 0 Then
VSTwain1.duplexEnabled = True ' enable duplex
End If
If VSTwain1.feederLoaded = 1 Then
VSTwain1.xferCount = -1
VSTwain1.autoFeed = True
VSTwain1.Acquire()
End If
End If
End If
End If
End Sub
Private Sub VSTwain1_PostScan(ByVal flag As Long)
If flag <> 0 Then
If VSTwain1.errorCode <> 0 Then
MsgBox VSTwain1.errorString
End If
Else
If VStwain1.SaveImage(VSTwain1.NumImages-1,"c:\test.tiff") = 0 Then
MsgBox VSTwain1.errorString
End If
If VSTwain1.dataSourceState = 0 Then
VSTwain1.StopDevice()
MsgBox "Scan completed."
End if
End If
End Sub
Whether can I create the console application using this component? You cannot create the console application with this ActiveX control. Your application must have own window for working with VintaSoftTwain ActiveX. How can I select necessary device without device selection dialog? You can use following code for enumerating your devices:
VSTwain1.StartDevice
For i = 0 To (VSTwain1.sourcesCount - 1)
MsgBox VSTwain1.GetSourceProductName(i)
Next
And this code for select the first device:
VSTwain1.StartDevice VSTwain1.sourceIndex = 0 ..... VSTwain1.AcquireBut the following way is the best:
VSTwain1.StartDevice
For i = 0 To (VSTwain1.sourcesCount - 1)
If VSTwain1.GetSourceProductName(i) = "Your device name" Then
VSTwain1.sourceIndex = i
Exit For
End If
Next
.....
In this case you must know correct device name.How can I disable progress indicator dialog when I acquire images without UI? TWAIN standard allows to disable the progress indicator dialog when showUI=False. This can be made as follows: VSTwain1.StartDevice VSTwain1.showUI = False VSTwain1.disableAfterAcquire = True VSTwain1.maxImages = 1 VSTwain1.OpenDataSource VSTwain1.showIndicators = 0 ' disable indicator window VSTwain1.Acquire I want to scan only a part of image. How can I do this? You can use following code for acquiring only a part of image limited by rectangle (0.2;0.2) - (8.3;10.8): VSTwain1.StartDevice() VSTwain1.showUI = False VSTwain1.OpenDataSource() ............. VSTwain1.unitOfMeasure = 0 ' inches VSTwain1.SetImageLayout(0.2,0.2,8.3,10.8) VSTwain1.Acquire() Can I set a different resolution in the X and Y direction? Yes. Here is the sample of code how to set X resolution to 4800 dpi and Y resolution to 9600 dpi: VSTwain1.StartDevice VSTwain1.showUI = False VSTwain1.disableAfterAcquire = True VSTwain1.maxImages = 1 VSTwain1.OpenDataSource VSTwain1.unitOfMeasure = 0 ' inches VSTwain1.capability = 4376 ' ICAP_XRESOLUTION (0x1118) VSTwain1.capType = 1 ' one value VSTwain1.capValue = 4800 ' 4800 dpi VSTwain1.SetCap VSTwain1.capability = 4377 ' ICAP_YRESOLUTION (0x1119) VSTwain1.capType = 1 ' one value VSTwain1.capValue = 9600 ' 9600 dpi VSTwain1.SetCap VSTwain1.Acquire How can I command the scanner to scan in Portrait or Landscape orientation? If scanner supports the ICAP_ORIENTATION capability then you can use it to scan in Landscape orientation as follows: .....
VSTwain1.OpenDataSource
VSTwain1.capability = 4368 ' ICAP_ORIENTATION (0x1110)
If VSTwain1.IsCapSupported Then
VSTwain1.capType = 1 ' one value
VSTwain1.capValue = 3 ' Landscape
VSTwain1.SetCap
End If
.....
Possible values for orientation:0 Portrait orientation, Rotation on 0 degrees 1 Rotation on 90 degrees 2 Rotation on 180 degrees 3 Landscape orientation, Rotation on 270 degrees Our organization has a network scanner with ADF and we scan many documents each day. How can we automate our work? We want to save each document in a separate file. You can use blank page for separation of documents and detect blank page, as delimiter of documents, by the IsBlankPage method. Here is an example:
Dim documentsCounter as Integer
............
documentsCounter = 0
............
Private Sub StartScan()
VSTwain1.StartDevice()
If VSTwain1.SelectSource() = 1 Then ' user selected the device
VSTwain1.showUI = False ' disable UI
VSTwain1.disableAfterAcquire = True
VSTwain1.maxImages = 1
VSTwain1.autoCleanBuffer = True
VSTwain1.tiffMultiPage = True ' multi page TIFF file
VSTwain1.tiffCompression = 10 ' auto detect of best compression algorithm
If VSTwain1.OpenDataSource() = 1 Then
VSTwain1.unitOfMeasure = 0 ' inches
VSTwain1.pixelType = 0 ' black-white image
VSTwain1.resolution = 200 ' 200 dpi
If VSTwain1.duplex <> 0 Then
VSTwain1.duplexEnabled = True ' enable duplex
End If
If VSTwain1.feederPresent = 1 Then
VSTwain1.xferCount = -1
VSTwain1.feederEnabled = True
VSTwain1.autoFeed = True
If VSTwain1.feederLoaded = 1 Then
VSTwain1.Acquire()
End If
End If
End If
End If
End Sub
Private Sub VSTwain1_PostScan(ByVal flag As Long)
If flag <> 0 Then
If VSTwain1.errorCode <> 0 Then
MsgBox VSTwain1.errorString
End If
Else
Dim currNoiseLevel As Single
If VSTwain1.IsBlankImage(0,0.01,currNoiseLevel) = 1 Then ' check the first image (page)
documentsCounter = documentsCounter + 1
End If
If VStwain1.SaveImage(0,"c:\documents\doc"+Str(documentsCounter)+".tiff") = 0 Then
MsgBox VSTwain1.errorString
End If
If VSTwain1.dataSourceState = 0 Then
VSTwain1.StopDevice()
MsgBox "Scan completed."
End if
End If
End Sub
Can I use patch codes to separate batch jobs? If so, how can I detect the end of batch job? You can detect batch jobs by using the CAP_JOBCONTROL capability. Here is an example for Visual Basic:
Dim jobsCounter As Integer
Private Sub Form_Load()
jobsCounter = -1
End Sub
Private Sub Scan_Click()
VSTwain1.StartDevice
VSTwain1.maxImages = 1
VSTwain1.showUI = 0
VSTwain1.disableAfterAcquire = 1
VSTwain1.tiffMultiPage = 1
VSTwain1.OpenDataSource
' 1 - Detect and include job separator and continue scanning.
' 3 - Detect and exclude job separator and continue scanning.
VSTwain1.jobControl = 1
jobsCounter = jobsCounter + 1
VSTwain1.Acquire
End Sub
Private Sub VSTwain1_PostScan(ByVal flag As Long)
If flag <> 0 Then
If VSTwain1.errorCode <> 0 Then
MsgBox (VSTwain1.errorString)
End If
Else
If VSTwain1.endOfJob = 1 Then
jobsCounter = jobsCounter + 1
Else
VSTwain1.SaveImage 0, "c:\job"+Str(jobsCounter)+".tif"
End If
End If
End Sub
.....
I should wait while the image acquisition process will be finished but I cannot use a PostScan event in my program. How can I solve this problem? You can use the AcquireModal method for solving this problem. Here is an example for Visual Basic:
VSTwain1.appProductName = "MyTwainApplication"
If VSTwain1.StartDevice() Then
VSTwain1.SelectSource
VSTwain1.showUI = True
While VSTwain1.AcquireModal() = 1
Set Image1.Picture = VSTwain1.GetCurrentImage()
If VSTwain1.SaveImage(0, "c:\test.tiff") = 0 Then
MsgBox (VSTwain1.errorString)
End If
Wend
Else
MsgBox VSTwain1.errorString
End If
Can I acquire 48-bit images? Yes. VintaSoftTwain ActiveX allows to acquire 48-bit color images or 16-bit gray images. Images can be saved without loss of bit depth only in TIFF files. When I am using HP Scanjet scanner, I am losing the top 1/2 inch of the scan - and there is an extra 1/2 inch of black space at the bottom of the scan. How can I solve this problem? You should switch value of the pageSize property from A4 to USLETTER and this will solve the problem. Can I store acquired images in OLE-field of MS Access's table? Yes. You can do this. For this purpose it's necessary to use a GetImageAsDIB method. Here is an example for MS Access ("OrderImage" is an OLE-field of table):
Option Compare Database
Option Explicit
Private Sub Form_AfterUpdate()
On Error GoTo error1
Image1.PictureData = Me![OrderImage]
Exit Sub
error1:
Image1.Picture = ""
End Sub
Private Sub Form_Current()
On Error GoTo error1
Image1.PictureData = Me![OrderImage]
Exit Sub
error1:
Image1.Picture = ""
End Sub
Private Sub BAcquire_Click()
With VSTwain1
.StartDevice
If .SelectSource = 1 Then
.autoCleanBuffer = 1
.maxImages = 1
.showUI = 1
.Acquire
End If
End With
End Sub
Private Sub VSTwain1_PostScan(ByVal flag As Long)
If flag <> 0 Then
If VSTwain1.errorCode <> 0 Then
MsgBox VSTwain1.errorString
End If
Else
If VSTwain1.numImages > 0 Then
If IsNull(Me!OrderName) Then ' a new record?
Me![OrderName] = " "
Me![OrderName] = "Order N" + Str(Me!Index)
End If
Me![OrderImage] = VSTwain1.GetImageAsDIB(0)
If VSTwain1.errorCode <> 0 Then
MsgBox VSTwain1.errorString
End If
Form.Refresh
End If
End If
End Sub
Can I store acquired images into a table of MS SQL server? Yes. You can do this. For this purpose it's necessary to use a GetImageAsDIB method. Here is an example for C# which illustrates how to save image into a table of local MS SQL server:
private void SaveToSql_Click(object sender, System.EventArgs e)
{
byte[] dib = (byte[]) VSTwain1.GetImageAsDIB(0);
int imageSize = 14 + dib.Length;
int imageOffset = 14 + 40;
int imageBPP = VSTwain1.GetImageBPP(0);
if (imageBPP == 1) imageOffset += 2*4;
else if (imageBPP == 8) imageOffset += 256*4;
byte[] image = new byte[imageSize];
Array.Clear(image,0,imageSize);
// BITMAPFILEHEADER
image[0] = (byte)'B';
image[1] = (byte)'M';
image[2] = (byte)(imageSize&0xFF);
image[3] = (byte)((imageSize&0xFF00)>>8);
image[4] = (byte)((imageSize&0xFF0000)>>16);
image[5] = (byte)((imageSize&0xFF000000)>>24);
image[10] = (byte)(imageOffset&0xFF);
image[11] = (byte)((imageOffset&0xFF00)>>8);
image[12] = (byte)((imageOffset&0xFF0000)>>16);
image[13] = (byte)((imageOffset&0xFF000000)>>24);
Array.Copy(dib,0,image,14,dib.Length);
// Insert the image into the database
SqlConnection myConnection = new SqlConnection (@"server=(local);
database=northwind;uid=sa;pwd=");
try
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand("DELETE FROM Images WHERE ImageID=1",
myConnection);
myCommand.ExecuteNonQuery();
myCommand = new SqlCommand ("INSERT INTO Images "
+ "(Image, ImageID) VALUES (@Image, @ImageID)", myConnection);
myCommand.Parameters.Add("@Image", image);
myCommand.Parameters.Add("@ImageID", 1);
myCommand.ExecuteNonQuery();
MessageBox.Show("Image is saved successfully.");
}
finally
{
myConnection.Close();
}
}
And here is an example for C# how to get image from a table of local MS SQL server:
private void BGetImageFromSql_Click(object sender, System.EventArgs e)
{
SqlConnection myConnection = null;
try
{
myConnection = new SqlConnection(@"server=(local);
database=northwind;uid=sa;pwd=");
SqlCommand myCommand = new SqlCommand("SELECT Image FROM Images WHERE ImageID=1",
myConnection);
myConnection.Open();
// Get the image from the database.
byte[] imagedata = (byte[])myCommand.ExecuteScalar();
if (imagedata != null)
{
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
pictureBox1.Image = null;
}
MemoryStream stream = new MemoryStream(imagedata);
pictureBox1.Image = new Bitmap(stream);
MessageBox.Show("Image is loaded successfully.");
}
else
{
MessageBox.Show("Image does not exist in database.");
}
}
finally
{
myConnection.Close();
}
}
I am using Visual FoxPro and the PostScan event is not firing. Why? The Application.AutoYield = .F. command needs to be set in Visual FoxPro where the program begins. |
|||||||||||