Product Info


Overview

Licensing

FAQ

Forums

Examples

History


Downloads

Evaluation version

On-line manual

Purchase

Buy now

Contact us

Testimonials


VintaSoftTwain ActiveX Control - Frequently Asked Questions

General questions:

 

Redistribution:

 

Deployment:

 

Web deployment:

 

Programming:

 

Databases:

 

 

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:

  • MS Visual Studio 6.0 (VB, VC++, VFoxpro)
  • Borland Delphi, Borland C++ Builder
  • MS .NET Studio (VB.NET, C#.NET, C++.NET)
  • MS Office (Excel, Word, Access)
  • any languages which support work with ActiveX controls.

With Server license you can use ActiveX in:

  • Internet Explorer 5.0 and higher : ASP.NET, PHP, JavaScript, VBScript, etc
  • Mozilla Firefox 3.0 and higher with IE Tab Plug-in : ASP.NET, PHP, JavaScript, VBScript, etc
  • any languages which are based on HTML.

 

 

What restrictions does the unregistered version have?

Unregistered version has the following restrictions:

  • nag screen
  • any image can be saved to a disk or uploaded onto server as BMP file
  • only black-white, gray or palette image can be saved to a disk or uploaded onto server as JPEG or TIFF file

All these restrictions are removed in registered version.

 

 

I have problems. What should I do?

Answers to most of questions can be found in the documentation or in this FAQ.

Please 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.

Site license has no limitations in re-distribution. Single Developer license has limitation in re-distribution. Server license is not royalty free. Please read the license agreementfor more info.

 


 

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:

  • Make sure before you distribute your project to remove from the "References" the AxVSTWAINLib and VSTWAINLib and re-insert them (Add Reference) from the default installation setup of VintaSoftTwain ActiveX.
  • Make sure that the Copy Local property of the AxVSTWAINLib.dll and VSTWAINLib.dll references is False.
  • After your program was compiled you must add three files to your distribution package: vstwain.dll, AxInterop.VSTWAINLib.dll, Interop.VSTWAINLib.dll (last two files will be generated by Visual Studio .Net).

When you distribute your program you need:

  • Check the installation of .NET framework. If the machine doesn't have the .NET framework then the dotnetfx.exe setup must be installed first of all. There is documentation about using ActiveX in .NET: "Using ActiveX Controls with Windows Forms in Visual Studio .NET Upgrading to Microsoft .NET" and about redistribution: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetdep/html/vsredistdeploy.asp
  • Further it is necessary to register the ActiveX (regsvr32.exe vstwain.dll).

 

 

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:

  • KERNEL32.DLL
  • ATL.DLL
  • GDI32.DLL
  • OLE32.DLL
  • OLEAUT32.DLL
  • SHELL32.DLL
  • USER32.DLL
  • WS2_32.DLL

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:

  • Start Visual Studio.NET with your own project
  • Open the main form in design view
  • Open Toolbox pane
  • Right mouse click on the Toolbox pane
  • Select "Add/Remove Items..." menu item from popup menu
  • Open COM Components tab
  • Click "Browse..." and select VSTwain.dll file
  • Find and check the VintaSoftTwain Class in the list
  • Close window using OK button
  • Find and select in the Toolbox pane VintaSoftTwain item
  • Place the VintaSoftTwain item on the form by selecting control rectangle

 

 

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:

  • Uninstall the ActiveX controls from the Tools Palette
  • Change to US Locale
  • Reboot
  • Reinstall the ActiveX control to the Tools Palette, and.. voila! It works.

 

 

How can I dynamically add VintaSoftTwain object in my VB project?

You must do following steps:

  • Go to menu "Project -> References".
  • In opened window you need to add reference to "VintaSoftTwain ActiveX Control" object.
  • 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:

  • Right mouse click on the "References"
  • Select "Add reference" menu item from popup menu
  • Open "COM" tab
  • Find and check the "OLE Automation" class in the list
  • Close window using OK button

After these steps you can add the VintaSoftTwain object to your form without any problems.

 

 

When I try to drag ActiveX control from the toolbox into the form in MS Visual Studio 2005, the following error occur: "Error message: Failed to import the ActiveX control". Is there a way to resolve this?

  • Drag VintaSoftTWAIN ActiveX Control from the toolbox to the form. This error will occur: "Failed to import the ActiveX control. Please ensure it is properly registered."
  • Rebuild the project, select "Build > Rebuild Solution".
  • Drag VintaSoftTWAIN ActiveX Control from the toolbox to the form for the second time. The known error will occur again.
  • Rebuild the project for the second time, select "Build > Rebuild Solution".
  • Drag VintaSoftTWAIN ActiveX Control from the toolbox to the form for the third time and the ActiveX control will be successfully imported.

 

 

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:

  • Add vstwain.dll file onto server.
  • 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.cab#version=5,1,0,1">
  </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.

VSTwain.cab file can be found in "Bin" directory of the distributive package.

 

 

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:

  • text field with a "Demo" name
  • file field with a "txtFile" name
  • button with a "cmdSubmit" name

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:

  • text field with a "login" name
  • text field with a "pass" name
  • file field with a "file" name

And you should use the following code for uploading images via this script:

  if VSTwain1.SetHttpServerParams("http://www.your-server.com/cgimages/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'm trying 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()

 

 

Can I use ActiveX in Mozilla Firefox?

Yes, you can use ActiveX in Mozilla Firefox 3.0 and higher with enabled IE Tab Plug-in.

 


 

How can I acquire black-white images?

Here is a sample of code for acquiring black-white images only:

  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
          Else
              MsgBox "Scan completed."
          End If
      Else
          If VSTwain1.SaveImage(VSTwain1.NumImages-1,"c:\test.tiff") = 0 Then
            MsgBox VSTwain1.ErrorString
          End If
      End If
  End Sub

 

 

Whether can I create the console application using this ActiveX control?

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.Acquire

But 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         ' select 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
          Else
              VSTwain1.StopDevice()
              MsgBox "Scan completed."
          End If
      Else
          Dim currNoiseLevel As Single
          If VSTwain1.IsBlankImage(0, 0.01, currNoiseLevel) = 1 Then
            documentsCounter = documentsCounter + 1
          End If
          If VStwain1.SaveImage(0,"c:\documents\doc"+Str(documentsCounter)+".tiff") = 0 Then
            MsgBox VSTwain1.ErrorString
          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.NET SDK 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.

Here is an example that demonstrates how to acquire 48-bpp color image without UI from scanner:
  VSTwain1.OpenDataSource()
  VSTwain1.PixelType = 2       ' RGB
  VSTwain1.Capability = 4395   ' IBitDepth
  VSTwain1.CapType = 1         ' One value
  VSTwain1.CapValue = 16       ' 16 bits per color component
  VSTwain1.SetCap()
  VSTwain1.Acquire()
Here is an example that demonstrates how to acquire 24-bpp color image without UI from scanner:
  VSTwain1.OpenDataSource()
  VSTwain1.PixelType = 2       ' RGB
  VSTwain1.Capability = 4395   ' IBitDepth
  VSTwain1.CapType = 1         ' One value
  VSTwain1.CapValue = 8        ' 8 bits per color component
  VSTwain1.SetCap()
  VSTwain1.Acquire()
Here is an example that demonstrates how to acquire 16-bpp gray image without UI from scanner:
  VSTwain1.OpenDataSource()
  VSTwain1.PixelType = 1       ' Gray
  VSTwain1.Capability = 4395   ' IBitDepth
  VSTwain1.CapType = 1         ' One value
  VSTwain1.CapValue = 16       ' 16 bits per color component
  VSTwain1.SetCap()
  VSTwain1.Acquire()

 

 

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.