Scanner SDK ActiveX

Scanner SDK ActiveX

Platform : Windows 10, Windows 8, Vista, Windows 7, XP

For Windows Developers who need to capture image from scanner, digital camera or capture card that has a TWAIN device driver with C , C#, VB.NET , VB, Delphi, Vfp, MS Access.

Popular Solution Go   Back

VB.NET - How to Scans pages from a TWAIN source and add overlay image to scanned documents

Step 1: To install the Scanner SDK ActiveX Control, begin by launching the setup file ( Select the desired installation folder for the Scanner ActiveX and continue with the installation on your development computer.

Step 2: Create New Visual Basic Project, select Windows Forms Application.

Step 3: The next step is to install Scanner ActiveX in ToolBox. Select Toolbox, select Components item, right click mouse button, select Choose Items...

Step 4: Select COM Components tab, select Scanner ActiveX Control , click OK.

Step 5: Now you will see the Scanner ActiveX's icon on toolbox, drag it to form.

Step 6: Add Combo box, four buttons , two textbox and label control, SaveFileDialog and OpenFileDialog control on form. Like the following picture. 

Step 7: In form load event, add the following code to add the image source item to combo box.

 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Dim iCount As Integer

        Dim i As Integer

        iCount = AxScanner1.GetNumImageSources()

        For i = 0 To iCount - 1



        If iCount > 0 Then

            cboscannerdevice.SelectedIndex = 0

        End If

End Sub

Step 8: add the following code in Scan button click event , it will capture the full page

Private Sub BtnScan_Click(sender As System.Object, e As System.EventArgs) Handles BtnScan.Click
        AxScanner1.DPI = 200
        AxScanner1.SetCaptureArea(0, 0, 0, 0)
        AxScanner1.BufferResizeMode = False
End Sub

Step 9: add the following code in Go button click event 

 Private Sub BtnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGo.Click
        BtnAddOverlay.Text = "Add Overlay Image on page " txtgopage.Text
 End Sub

Step 10: add the following code , it will convert the color to uint32 format

    Public Function Color2Uint32(ByVal clr As Color) As UInt32
        Dim t As Int32
        Dim a() As Byte
        t = ColorTranslator.ToOle(clr)
        a = BitConverter.GetBytes(t)
        Return BitConverter.ToUInt32(a, 0)
    End Function 

Step 11: add the following code in Add Overlay image button click event, it will add the overlay image in active page. set the image size to 128x128

 Private Sub BtnAddOverlay_Click(sender As System.Object, e As System.EventArgs) Handles BtnAddOverlay.Click
        OpenFileDialog1.Filter = "PNG Files (*.png)|*.png|JPEG Files (*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp|GIF Files (*.gif)|*.gif|TIFF Files (*.tif)|*.tif;..."
        Dim i As Integer
        Dim clrTran As Color
        clrTran = Color.Black
enFileDialog1.ShowDialog() = DialogResult.OK Then
             AxScanner1.DrawOverlayImage(0, 0, 128, 128, OpenFileDialog1.FileName, Color2Uint32(clrTran))
        End If
    End Sub

Step 12:select the Scanner Control, Click Event icon in Properties Windows, double EndScan Event to add the EndScan Event hander.

Step 13: In EndScan event handler , add the following code to get the total scanned page to textbox 
 Private Sub AxScanner1_EndScan(sender As System.Object, e As System.EventArgs) Handles AxScanner1.EndScan
        txttotalpage.Text = AxScanner1.TotalPage.ToString()
 End Sub

Step 14: Now run the project, select the scanner device, click Scan button, Go to specific scanned page, click Add Overlay Image on page button then click Save to PDF button.

Download this sample source code