| Home | Download | Register | Testimonials | Support |
|
|||||||||||||||||||
|
VintaSoftTwain.NET Library For which purposes can I use the VintaSoftTwain.NET Library? The library can be used for controlling a work of scanners, web or digital cameras and any other TWAIN devices. From which parts does the library consist? The library contains:
In which programming languages can I use the VintaSoft.Twain component? With Single Developer license or Site license you can use component in: With Server license you can use component 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. What files do I need to include in the setup package of my program? You need include only one file: VintaSoft.Twain.dll. This file must be placed in the same folder as the assembly that references it. Make sure that the version you distribute is the version your assembly was compiled with. Can I re-distribute the VintaSoft.Twain.dll with my application without royalties? Yes, this component is royalty free. You pay only for registration one time. Only this componet can be re-distributed with your application. Single Developer license has limitation in re-distribution. Please see license agreement. How can I add the VintaSoft.Twain component to a form in my project? To add VintaSoft.Twain component to your form you should do the following: 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 Then
VSTwain1.OpenDataSource
VSTwain1.PixelType = PixelType.BW
VSTwain1.Acquire
End If
End Sub
How can I work with ADF without displaying the 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()
VSTwain1.SelectSource()
VSTwain1.ShowUI = false
VSTwain1.DisableAfterAcquire = true
VSTwain1.MaxImages = 1
VSTwain1.AutoCleanBuffer = true
VSTwain1.OpenDataSource()
VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches
VSTwain1.PixelType = PixelType.RGB
VSTwain1.Resolution = 200
VSTwain1.TiffMultiPage = true
VSTwain1.TiffCompression = TiffCompression.Auto
If VSTwain1.Duplex <> DuplexMode.None Then
VSTwain1.DuplexEnabled = true ' enable Duplex
End If
If VSTwain1.FeederPresent Then
VSTwain1.FeederEnabled = true
VSTwain1.AutoFeed = true
VSTwain1.XferCount = -1
If VSTwain1.FeederLoaded Then
VSTwain1.Acquire()
Endif
Endif
End Sub
Private Sub VSTwain1_PostScan(ByVal sender As Object,
ByVal e As VintaSoft.Twain.PostScanEventArgs)
Handles VSTwain1.PostScan
If Not e.Flag Then
If VSTwain1.ErrorCode <> 0 Then
MsgBox VSTwain1.ErrorString
End If
Else
If Not (VStwain1.SaveImage(0,"c:\test.tiff") Then
MsgBox VSTwain1.ErrorString
End If
If VSTwain1.DataSourceState = DataSourceState.Closed Then
VSTwain1.StopDevice()
MsgBox "Scan completed."
Endif
End If
End Sub
How can I work with ADF without displaying the User Interface and without the PostScan event? Here is a sample of code to drive a scanner with an ADF without the Data Source user interface:
Private Sub StartScan()
VSTwain1.StartDevice()
VSTwain1.SelectSource()
VSTwain1.ShowUI = false
VSTwain1.DisableAfterAcquire = true
VSTwain1.MaxImages = 1
VSTwain1.AutoCleanBuffer = true
VSTwain1.OpenDataSource()
VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches
VSTwain1.PixelType = PixelType.RGB
VSTwain1.Resolution = 200
VSTwain1.TiffMultiPage = true
VSTwain1.TiffCompression = TiffCompression.Auto
If VSTwain1.Duplex <> DuplexMode.None Then
VSTwain1.DuplexEnabled = true ' enable Duplex
End If
If VSTwain1.FeederPresent Then
VSTwain1.FeederEnabled = true
VSTwain1.AutoFeed = true
VSTwain1.XferCount = -1
If VSTwain1.FeederLoaded Then
While VSTwain1.AcquireModal()
If Not VStwain1.SaveImage(0,"c:\test.tiff") Then
MsgBox VSTwain1.ErrorString
End If
End While
VSTwain1.StopDevice()
MsgBox "Scan completed."
Endif
Endif
End Sub
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.5,0.5) - (6,8): VSTwain1.StartDevice() VSTwain1.ShowUI = False VSTwain1.OpenDataSource() ............. VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches VSTwain1.SetImageLayout(0.5,0.5,6,8) VSTwain1.Acquire() How can I select a device without displaying the 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 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
break
End If
Next
.....
In this case you must know correct device name.How can I disable the 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 VSTwain1.Acquire I want to create my own progress indicator of image scan. Is this possible? Yes, this is possible if you use a Memory transfer mode - you should use a Progress event. Here is an example: Private Sub VSTwain1_ImageProcessingProgress(ByVal sender As Object, _
ByVal e As VintaSoft.Twain.ProgressEventArgs) _
Handles VSTwain1.Progress
If e.action = Action.Deskew Then
txtAction.Text = "Deskewing..."
ElseIf e.action = Action.Despecle Then
txtAction.Text = "Despeckling..."
ElseIf e.action = Action.BorderDetection Then
txtAction.Text = "Border detecting..."
ElseIf e.action = Action.Rotation Then
txtAction.Text = "Rotating..."
ElseIf e.action = Action.ImageScan Then
txtAction.Text = "Image scan..."
End If
progressBar1.Value = e.percentComplete
e.interrupt = bFinishFlag
End Sub
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 = UnitOfMeasure.Inches VSTwain1.Capability = Capability.IXResolution VSTwain1.CapType = CapType.OneValue VSTwain1.CapValue = 4800 ' 4800 dpi VSTwain1.SetCap VSTwain1.Capability = Capability.IYResolution VSTwain1.CapType = CapType.OneValue VSTwain1.CapValue = 9600 ' 9600 dpi VSTwain1.SetCap VSTwain1.Acquire I want to scan documents in a separate thread. Is it possible? Yes, it is possible if the AcquireModal method will be used. Here is an example for C#:
.....
public class Form1 : System.Windows.Forms.Form
{
private VSTwain twain=null;
.....
private void buttonScanASync_Click(object sender, System.EventArgs e)
{
ThreadStart ts = new ThreadStart(this.doScanning);
Thread t = new Thread(ts);
t.Name = "Scan-Thread";
t.Start();
}
private void doScanning()
{
twain = new VSTwain();
if (twain.StartDevice())
{
twain.ShowUI = false;
if (twain.SelectSource())
{
while (twain.AcquireModal())
{
pictureBox.Image = twain.GetCurrentImage();
}
}
twain.StopDevice();
}
}
.....
}
.....
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
VSTwain1.ShowUI = false
VSTwain1.DisableAfterAcquire = true
VSTwain1.MaxImages = 1
VSTwain1.AutoCleanBuffer = true
VSTwain1.TiffMultiPage = true
VSTwain1.TiffCompression = TiffCompression.Auto
If VSTwain1.OpenDataSource() = 1 Then
VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches
VSTwain1.PixelType = PixelType.GRAY
VSTwain1.Resolution = 200 ' 200 dpi
If VSTwain1.Duplex <> DuplexMode.None Then
VSTwain1.DuplexEnabled = true
End If
If VSTwain1.FeederPresent Then
VSTwain1.XferCount = -1
VSTwain1.FeederEnabled = true
VSTwain1.AutoFeed = true
If VSTwain1.FeederLoaded 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
' check the first image (page)
If VSTwain1.IsBlankImage(0) Then
documentsCounter = documentsCounter + 1
End If
If Not VStwain1.SaveImage(0,"c:\documents\doc"+
Str(documentsCounter)+".tiff") 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 .NET:
Dim jobsCounter As Integer
Private Sub Form_Load()
jobsCounter = -1
End Sub
Private Sub Scan_Click()
VSTwain1.StartDevice
VSTwain1.MaxImages = 1
VSTwain1.ShowUI = false
VSTwain1.DisableAfterAcquire = true
VSTwain1.TiffMultiPage = true
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 sender As System.Object,
ByVal e As VintaSoft.Twain.PostScanEventArgs) Handles VSTwain1.PostScan
If Not e.Flag Then
If VSTwain1.ErrorCode <> 0 Then
MsgBox(VSTwain1.ErrorString)
End If
Else
If VSTwain1.EndOfJob Then
jobsCounter = jobsCounter + 1
Else
VSTwain1.SaveImage 0, "c:\job"+jobsCounter.ToString()+".tif"
End If
End If
End Sub
.....
I want to store acquired images in collection and then process them. How can I do this? If you want to store acquired images in your own buffer (for example in Collection object in VB.NET), then you must create a full copy of image object returned by the GetImage method, and place it to your buffer. You cannot place to the buffer an image object returned by the GetImage method because this object will be destroyed when you will acquire new image or when you will call the StopDevice method. Here is correct code: ... Dim colDocumentPages As New Collection ... Dim picNewPage As Image = New Bitmap(vnsScanner.GetCurrentImage) colDocumentPages.Add(picNewPage) ...And here is not correct code: ... Dim colDocumentPages As New Collection ... Dim picNewPage As Image picNewPage = vnsScanner.GetCurrentImage colDocumentPages.Add(picNewPage) ... 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. What steps should I make to add the VintaSoft.Twain Component to my web project? On Server side you must do the following:
On Client side you must do the following:
VSTwain1.StartDevice() VSTwain1.object.SourceIndex = 1 ' second device VSTwain1.Acquire() Can I store acquired images into a table of MS SQL server? Yes, you can do this, please see example 3 here. |
||||||||||||||||||||