VintaSoft Twain .NET SDK v10.2
Upgrading guide from version 6.0 to 7.0

How to upgrade your code from version 6.0 to 7.0


Programmers who currently use VintaSoft Twain .NET SDK 6.0 may be a little confused of upgrading to the version 7.0 due to the fact that this require several changes in their code.

VintaSoft developers always try to accommodate the wishes of clients and implement them in new versions and new products. Our products always evolve to meet the needs of the most exacting customers. Please take with understanding all changes we made only with one reason - make the product faster, more reliable and advanced.

This upgrading guide will provide you the list of methods and properties which were changed, renamed or deleted in version 7.0 to improve the SDK.

Namespaces changes:

Vintasoft.Twain Removed classes.

Vintasoft.Twain.VSTwain

Vintasoft.Twain Added classes.

Vintasoft.Twain.DeviceManager

Class that allows to manipulate TWAIN device manager.
Vintasoft.Twain.DeviceManagerLogger Class that allows to log the work of the TWAIN device.
Vintasoft.Twain.Device Class that allows to manipulate TWAIN device.
Vintasoft.Twain.DocumentFeeder Class that allows to manipulate the automatic document feeder of TWAIN device.
Vintasoft.Twain.DeviceImageLayout Class that allows to manipulate the image layout of TWAIN device.
Vintasoft.Twain.DeviceCapabilitiesCollection Class that represents a collection of capabilities supported by device.
Vintasoft.Twain.DeviceCapability Class that allows to manipulate the device capability.
Vintasoft.Twain.AcquiredImageCollection Class that represent the collection of images acquired from TWAIN device.
Vintasoft.Twain.AcquiredImage Class that represents image acquired from TWAIN device.
Vintasoft.Twain.ImageInfo Class that contains information about acquired image.
Vintasoft.Twain.TwainException Base class for all exceptions that can occur during work with TWAIN device manager or device.
Vintasoft.Twain.TwainDeviceManagerException Represents errors that occur during work with the TWAIN device manager.
Vintasoft.Twain.TwainDeviceException Represents errors that occur during work with the TWAIN device.
Vintasoft.Twain.TwainInvalidStateException Represents errors that occur if TWAIN device manager or device is in wrong state.
Vintasoft.Twain.TwainDeviceCapabilityException Represents errors that occur during work with the TWAIN device capability.
Vintasoft.Twain Added structs.

Vintasoft.Twain.DeviceInfo

Information about the device.



Compliance list between constructors of VSTwain object from version 6.0 and objects from version 7.0:


Version 6.0 Version 7.0
VSTwain() DeviceManager(),
DeviceManager(parentForm)


Compliance list between properties of VSTwain object from version 6.0 and objects from version 7.0:


Version 6.0 Version 7.0
VSTwain.AllowExceptions Removed
VSTwain.AppProductName DeviceManager.ApplicationProductName
VSTwain.AutoBright Device.AutoBright
VSTwain.AutoCleanBuffer AcquiredImageCollection.AutoClean
VSTwain.AutoFeed DocumentFeeder()
VSTwain.AutoSize Device.PageAutoSize
VSTwain.Brightness Device.Brightness
VSTwain.BrightnessMaxValue Device.GetBrightnessValues()
VSTwain.BrightnessMinValue Device.GetBrightnessValues()
VSTwain.CancelTransfer Device.CancelTransfer()
VSTwain.Capability DeviceCapability.Id
VSTwain.CapDefValue DeviceCapability.GetValues
VSTwain.CapItems DeviceCapability.GetValues
VSTwain.CapMaxValue DeviceCapability.GetValues
VSTwain.CapMinValue DeviceCapability.GetValues
VSTwain.CapStepSize DeviceCapability.GetValues
VSTwain.CapType Removed
VSTwain.CapValue DeviceCapability.GetValue
VSTwain.CapValueType DeviceCapability.ValueType
VSTwain.Contrast Device.Contrast
VSTwain.ContrastMaxValue Device.GetSupportedContrastValues()
VSTwain.ContrastMinValue Device.GetSupportedContrastValues()
VSTwain.DataSourceState Device.State
VSTwain.DeviceOnline Device.Online
VSTwain.DisableAfterAcquire Device.DisableAfterAcquire
VSTwain.DuplexEnabled DocumentFeeder.DuplexEnabled
VSTwain.Duplex DocumentFeeder.DuplexMode
VSTwain.EndOfJob Device.EndOfJob
VSTwain.ErrorCode Removed
VSTwain.ErrorString DeviceManager.ErrorString
VSTwain.ExtendedImageInfoCollection Device.ExtendedImageInfo
VSTwain.FeederEnabled DocumentFeeder.Enabled
VSTwain.FeederLoaded DocumentFeeder.Loaded
VSTwain.FeederPresent Device.FeederPresent
VSTwain.FileName Device.FileName
VSTwain.FileFormat Device.FileFormat
VSTwain.FlatbedPresent Device.FlatbedPresent
VSTwain.IsLoggingEnabled DeviceManagerLogger.Enabled
VSTwain.IsTwain2Compatible DeviceManager.IsTwain2Compatible
VSTwain.IsTwainAvailable DeviceManager.IsTwainAvailable
VSTwain.JobControl Device.JobControl
VSTwain.JpegQuality AcquiredImageCollection.JpegQuality
VSTwain.LogFilePath DeviceManagerLogger.Filename
VSTwain.MaxImages AcquiredImageCollection.Capacity
VSTwain.ModalUI Device.ModalUI
VSTwain.NumImages AcquiredImageCollection.Count
VSTwain.Orientation Device.Orientation
VSTwain.PageSize Device.PageSize
VSTwain.PaperDetectable DocumentFeeder.PaperDetectable
VSTwain.Parent DeviceManager(parentForm)
VSTwain.PdfACompatible AcquiredImageCollection.PdfACompatible
VSTwain.PdfDocumentInfo AcquiredImageCollection.PdfDocumentInfo
VSTwain.PdfImageCompression AcquiredImageCollection.PdfImageCompression
VSTwain.PdfMultiPage AcquiredImageCollection.PdfMultiPage
VSTwain.PixelFlavor Device.PixelFlavor
VSTwain.PixelType Device.PixelType
VSTwain.Resolution Device.Resolution,
Device.SetResolution()
VSTwain.ShowUI Device.ShowUI
VSTwain.SourcesCount DeviceManager.Devices.Count
VSTwain.SourceIndex DeviceManager.Devices.CurrentIndex
VSTwain.TiffMultiPage AcquiredImageCollection.TiffMultiPage
VSTwain.TiffCompression AcquiredImageCollection.TiffCompression
VSTwain.TransferMode Device.TransferMode
VSTwain.TwainDllPath DeviceManager.TwainDllPath
VSTwain.UnitOfMeasure Device.UnitOfMeasure
VSTwain.Version TwainGlobalSettings.Version
VSTwain.XferCount Device.XferCount


Compliance list between methods of VSTwain object from version 6.0 and objects from version 7.0:


Version 6.0 Version 7.0
VSTwain.Acquire() Device.Acquire()
VSTwain.AcquireModal() Device.AcquireModal()
VSTwain.CloseDataSource() Device.Close()
VSTwain.DeleteImage(index) Device.AcquiredImages.RemoveAt(index)
VSTwain.DeskewImage(index, borderColor, scanIntervalX, scanIntervalY) AcquiredImage.Deskew(borderColor, scanIntervalX, scanIntervalY)
VSTwain.DespeckleImage(index, level1, level2, radius, level3) AcquiredImage.Despeckle(index, level1, level2, radius, level3)
VSTwain.DetectImageBorder(index, borderSize, scanIntervalX, scanIntervalY) AcquiredImage.DetectBorder(borderSize)
VSTwain.Dispose() DeviceManager.Dispose()
VSTwain.GetCap() DeviceCapability.GetValue()
VSTwain.GetCapUsageMode() DeviceCapability.GetUsageMode()
VSTwain.GetCurrentImage() AcquiredImageCollection.Last.GetAsBitmap()
VSTwain.GetImage(index) Device.AcquiredImages[index].GetAsBitmap()
VSTwain.GetImageAsStream(index, imageFileFormat) Device.AcquiredImages[index].GetAsStream()
VSTwain.GetImageBpp(index) AcquiredImage.BitCount
VSTwain.GetImageHeight(index) AcquiredImage.Height
VSTwain.GetImageLayout(left, top, right, bottom) Device.ImageLayout.Get(left, top, right, bottom)
VSTwain.GetImageLayout() Device.ImageLayout.GetAsString()
VSTwain.GetImageWidth(index) AcquiredImage.Width
VSTwain.GetImageXRes(index) AcquiredImage.Resolution.Horizontal
VSTwain.GetImageYRes(index) AcquiredImage.Resolution.Vertical
VSTwain.GetPageSizes() Device.GetSupportedPageSizes()
VSTwain.GetPathToTempDir() DeviceManager.GetPathToTempDir()
VSTwain.GetPixelTypes() Device.GetSupportedPixelTypes()
VSTwain.GetResolutions() Device.GetSupportedHorizontalResolutions(),
Device.GetSupportedVerticalResolutions()
VSTwain.GetSourceInfo(index) Device.Info
VSTwain.GetUnitsOfMeasure() Device.GetSupportedUnitsOfMeasure()
VSTwain.IsBlankImage(index, maxNoiseLevel, currentNoiseLevel) AcquiredImage.IsBlank(maxNoiseLevel, currentNoiseLevel)
VSTwain.IsCapSupported() Removed - does not necessary any more because device has collection of supported capabilities
VSTwain.LoadDeviceSettings(stream) Device.Capabilities.Load(stream)
VSTwain.LoadCustomDeviceSettings(stream) Device.LoadSettings(stream)
VSTwain.OpenDataSource() Device.Open()
VSTwain.RotateImage(index, angle, borderColor) AcquiredImage.Rotate(angle, borderColor)
VSTwain.SaveCustomDeviceSettings(stream) Device.SaveSettings(stream)
VSTwain.SaveDeviceSettings(stream) Device.Capabilities.Save(stream)
VSTwain.SaveImage(index, filename) AcquiredImage.Save(filename)
VSTwain.SaveImageToStream(index, stream, imageFileFormat) AcquiredImage.SaveImageToStream(stream, imageFileFormat)
VSTwain.SelectSource() DeviceManager.Devices.Select()
VSTwain.SetCap() DeviceCapability.SetValue(...)
VSTwain.SetImageLayout(left, top, right, bottom) Device.ImageLayout.Set(left, top, right, bottom)
VSTwain.SetImageLayout(string rectangle) Device.ImageLayout.Set(string frame)
VSTwain.SetupSource() Device.Setup()
VSTwain.StartDevice DeviceManager.Open()
VSTwain.StopDevice() DeviceManager.Close()
VSTwain.SwapImages(firstIndex, secondIndex) AcquiredImageCollection.Swap(firstIndex, secondIndex)


Compliance list between events of VSTwain object from version 6.0 and objects from version 7.0:


Version 6.0 Version 7.0
VSTwain.ImageAcquired Device.ImageAcquired
VSTwain.ScanCompleted Device.ScanCompleted,
Device.ScanCanceled,
Device.ScanFailed,
Device.UserInterfaceClosed
VSTwain.ProgressChanged Device.ImageAcquiringProgress,
AcquiredImage.Progress


Code convertation examples:


Version 6.0 Version 7.0
Public Sub AcqiuireImagesAsynchronouslyWithUI()
    ' set the application name
    VSTwain1.AppProductName = "MyTwainApplication"
    Try
        ' initialize the library
        VSTwain1.StartDevice()
        ' show "Select Source" dialog
        VSTwain1.SelectSource()
        ' enable the user interface (false - disable the user interface)
        VSTwain1.ShowUI = True
        ' start asynchronous acquisition process
        VSTwain1.Acquire()
    Catch ex As TwainException
        MsgBox ex.Message
    End Try
End Sub

Private Sub VSTwain1_ImageAcquired(ByVal sender As Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles VSTwain1.ImageAcquired
    ' dispose previous image if picture box has it
    If Not (PictureBox1.Image Is Nothing) Then
        PictureBox1.Image.Dispose()
        PictureBox1.Image = Nothing
    End If
    ' show acquired image in the picture box
    PictureBox1.Image = VSTwain1.GetCurrentImage()
End Sub

Private Sub VSTwain1_ScanCompleted(ByVal sender As Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles VSTwain1.ScanCompleted
    ' show error message if error occur
    If VSTwain1.ErrorCode <> ErrorCode.None Then
        MsgBox(VSTwain1.ErrorString)
        ' show message "Scan process is completed."
    Else
        MsgBox("Scan process is completed.")
    End If
End Sub
Private Sub scanButton_Click(ByVal sender As System.Object, _
                             ByVal e As System.EventArgs) Handles scanButton.Click
    Try
        ' create TWAIN device manager
        _deviceManager = New DeviceManager(Me)
        ' set the application name
        _deviceManager.ApplicationProductName = "MyTwainApplication"
        ' open device manager
        _deviceManager.Open()

        ' show "Select Source" dialog
        _deviceManager.Devices.Select()

        ' get reference to current device
        _device = _deviceManager.Devices.Current
        ' create handlers of events
        AddHandler _device.ImageAcquired, AddressOf _device_ImageAcquired
        AddHandler _device.ScanCompleted, AddressOf _device_ScanCompleted
        AddHandler _device.ScanCanceled, AddressOf _device_ScanCanceled
        AddHandler _device.ScanFailed, AddressOf _device_ScanFailed
        AddHandler _device.UserInterfaceClosed, AddressOf _device_UserInterfaceClosed

        ' set scanning settings
        _device.ShowUI = True

        ' acquire images from device
        _device.Acquire()
    Catch ex As TwainException
        MsgBox(ex.Message)
    End Try
End Sub

Private Sub _device_ImageAcquired(ByVal sender As System.Object, _
                                  ByVal e As Vintasoft.Twain.ImageAcquiredEventArgs)
    ' dispose previous image if picture box has it
    If Not (PictureBox1.Image Is Nothing) Then
        PictureBox1.Image.Dispose()
        PictureBox1.Image = Nothing
    End If
    ' show acquired image in the picture box
    PictureBox1.Image = e.Image.GetAsBitmap()
End Sub

Private Sub _device_ScanCompleted(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs)
    ' UI is enabled, we need to wait for the UserInterfaceClosed event
End Sub

Private Sub _device_ScanCanceled(ByVal sender As System.Object, _
                                 ByVal e As System.EventArgs)
    ' close the device
    _device.Close()
    MsgBox("Scan canceled.")
End Sub

Private Sub _device_ScanFailed(ByVal sender As System.Object, _
                               ByVal e As Vintasoft.Twain.ScanFailedEventArgs)
    ' close the device
    _device.Close()
    MsgBox("Scan failed: " + e.ErrorString)
End Sub

Private Sub _device_UserInterfaceClosed(ByVal sender As System.Object, _
                                        ByVal e As System.EventArgs)
    ' close the device
    _device.Close()
    MsgBox("Scan process is completed.")
End Sub
Public Sub AcqiuireImagesSynchronouslyWithoutUI()
     ' set the application name
     VSTwain1.AppProductName = "MyTwainApplication"
     Try
         ' initialize the library
         VSTwain1.StartDevice()

         ' show "Select Source" dialog
         VSTwain1.SelectSource()

         ' disable the user interface
         VSTwain1.ShowUI = False

         ' open the data source
         VSTwain1.OpenDataSource()
         ' set inches as the units of measure
         VSTwain1.UnitOfMeasure = UnitOfMeasure.Inches
         ' acquire black-white images
         VSTwain1.PixelType = PixelType.BW
         ' set the resolution
         VSTwain1.Resolution = 300

         ' acquire images
         While VSTwain1.AcquireModal()
             ' dispose previous image if picture box has it
             If Not (PictureBox1.Image Is Nothing) Then
                 PictureBox1.Image.Dispose()
                 PictureBox1.Image = Nothing
             End If
             ' show acquired image in the picture box
             PictureBox1.Image = VSTwain1.GetCurrentImage()
             ' save acquired image to a file
             VSTwain1.SaveImage 0, "c:\test.tiff"
         End While
     Catch ex As TwainException
         MsgBox ex.Message
     Catch ex As ImagingException
         MsgBox ex.Message
     End Try
End Sub
Friend Shared Sub Main(args As String())
    Try
        Using deviceManager As New DeviceManager()
            ' open the device manager
            deviceManager.Open()

            ' get reference to the current device
            Dim device As Device = deviceManager.Devices.Current

            ' open the device
            device.Open()

            ' set acquisition parameters
            device.ShowUI = False
            device.DisableAfterAcquire = True
            device.PixelType = PixelType.BW
            device.UnitOfMeasure = UnitOfMeasure.Inches
            device.Resolution = New Resolution(300, 300)

            ' acquire image(s) from the device
            Dim acquireModalState1 As AcquireModalState = AcquireModalState.None
            Dim imageIndex As Integer = 0
            Do
                acquireModalState1 = device.AcquireModal()
                Select Case acquireModalState1
                    Case AcquireModalState.ImageAcquired
                        ' save image to file
                        device.AcquiredImages.Last.Save("c:\test.tiff")

                    Case AcquireModalState.ScanCompleted
                        ' close device and device manager
                        CloseDeviceAndDeviceManager(deviceManager, device)
                        ' output current state
                        Console.WriteLine("Scan completed.")

                    Case AcquireModalState.ScanCanceled
                        ' close device and device manager
                        CloseDeviceAndDeviceManager(deviceManager, device)
                        ' output current state
                        Console.WriteLine("Scan canceled.")

                    Case AcquireModalState.ScanFailed
                        ' close device and device manager
                        CloseDeviceAndDeviceManager(deviceManager, device)
                        ' output current state
                        Console.WriteLine(String.Format("Scan failed: {0}", _
                                                  deviceManager.ErrorString))
                End Select
            Loop While acquireModalState1 <> AcquireModalState.None
        End Using
    Catch ex As TwainException
        Console.WriteLine("Error: " + ex.Message)
    End Try

    Console.ReadLine()
End Sub

' Close device and device manager.
Private Shared Sub CloseDeviceAndDeviceManager(deviceManager As DeviceManager, _
                                               device As Device)
    If device.State = DeviceState.Opened Then
        ' close the device
        device.Close()
    End If

    ' close the device manager
    deviceManager.Close()
End Sub