Set scan area

Questions, comments and suggestions concerning VintaSoft Twain ActiveX.

Moderator: Alex

Post Reply
easyonex
Posts: 2
Joined: Mon Jun 05, 2023 6:21 pm

Set scan area

Post by easyonex »

Hello.

I got the ActiveX a few days ago to update an older VB6 project with it.

So far everything works quite well. But I would like to be able to set the scan range, in millimeters!

Unfortunately it always stays in inches!?

Code: Select all

    ' Einheit festlegen
    VSTwain1.Device_UnitOfMeasure = UNITOFMEASURE_Millimeters

    ' Scanbereich festlegen
    VSTwain1.Device_SetImageLayout 0, 0, 50, 110
Thank you for your answers.

Andreas
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Set scan area

Post by Alex »

Hello Andreas,

Our support team already answered to you question. I hope problem is solved.

Best regards, Alexander
easyonex
Posts: 2
Joined: Mon Jun 05, 2023 6:21 pm

Re: Set scan area

Post by easyonex »

Hello.

No, unfortunately not. I have set Device_PageSize property to 0 and also used Device_GetSupportedUnitsOfMeasure. However, the result remains the same. The unit remains in inches. I currently have the millimeters converted to inches until I solve the problem. See source code.

Code: Select all

    ' disable application UI
    scanImagesButton.Enabled = False

    ' try to use TWAIN device manager 2.x
    VSTwain1.DeviceManager_IsTwain2Compatible = twain2CheckBox.Value
    ' if TWAIN device manager 2.x is not available
    If Not VSTwain1.DeviceManager_IsAvailable Then
        ' try to use TWAIN device manager 1.x
        VSTwain1.DeviceManager_IsTwain2Compatible = Not twain2CheckBox.Value
        ' if TWAIN device manager 1.x is not available
        If Not VSTwain1.DeviceManager_IsAvailable Then
            MsgBox "TWAIN device manager is not available."
            ' enable application UI
            scanImagesButton.Enabled = True
            Exit Sub
        End If
    End If

    VSTwain1.Register "User", "Email", "Serial"

    ' open the device manager
    If Not VSTwain1.DeviceManager_Open() Then
        MsgBox VSTwain1.errorString
        ' enable application UI
        scanImagesButton.Enabled = True
        Exit Sub
    End If

    ' if no devices are found in the system
    If VSTwain1.DeviceManager_DeviceCount = 0 Then
        MsgBox "Devices are not found."
        ' enable application UI
        scanImagesButton.Enabled = True
        Exit Sub
    End If

    ' if device is NOT selected
    If Not VSTwain1.DeviceManager_ShowDefaultDeviceSelectionDialog() Then
        MsgBox "Device is not selected."
        ' enable application UI
        scanImagesButton.Enabled = True
        Exit Sub
    End If

    ' select the device selected by user
    VSTwain1.DeviceManager_SelectedDeviceIndex = VSTwain1.DeviceManager_DefaultDeviceIndex
    If VSTwain1.Error Then
        MsgBox VSTwain1.errorString
        ' enable application UI
        scanImagesButton.Enabled = True
        Exit Sub
    End If

    ' open the device
    VSTwain1.Device_Open
    If VSTwain1.Error Then
        MsgBox VSTwain1.errorString
        ' enable application UI
        scanImagesButton.Enabled = True
        Exit Sub
    End If
   
    VSTwain1.Device_GetSupportedUnitsOfMeasure
    VSTwain1.Device_PageSize = 0

    ' set scan settings
    VSTwain1.Device_ShowUI = False ' showUiCheckBox.Value
    VSTwain1.Device_ShowIndicators = showIndicatorsCheckBox.Value
    VSTwain1.Device_DisableAfterAcquire = Not VSTwain1.Device_ShowUI
    VSTwain1.Device_TransferMode = TRANSFERMODE_Memory

    ' Scanbereich auslesen
    Dim nLeft As Single, nTop As Single, nRight As Single, nBottom As Single
    VSTwain1.Device_GetImageLayout nLeft, nTop, nRight, nBottom 
   
    nLeft = 0
    nTop = 0
    nRight = 210
    nBottom = 297

    ' Scanbereich festlegen
    VSTwain1.Device_SetImageLayout nLeft, nTop, nRight, nBottom

    VSTwain1.Device_ImagePixelType = PIXELTYPE_Gray
    VSTwain1.Device_ImageBitDepth = 16
    

    ' acquire image(s) from the device
    Dim acquireModalState1 As ACQUIREMODALSTATE
    Do
      acquireModalState1 = VSTwain1.Device_AcquireImageModal
      Select Case acquireModalState1
        Case VSTwainLibCtl.ACQUIREMODALSTATE_ImageAcquired
          ' set a bitmap in the picture box
          Set Image1.Picture = VSTwain1.AcquiredImages_GetImage(0)

          imageCount = imageCount + 1
          totalImageCount = totalImageCount + 1

          ' dispose an acquired image
          VSTwain1.AcquiredImages_Clear

        Case VSTwainLibCtl.ACQUIREMODALSTATE_ScanCanceled
          MsgBox "Scan is canceled."

        Case VSTwainLibCtl.ACQUIREMODALSTATE_ScanFailed
          MsgBox "Scan is failed: " + VSTwain1.errorString

      End Select
    Loop While acquireModalState1 <> VSTwainLibCtl.ACQUIREMODALSTATE_None

    ' close the device
    VSTwain1.Device_Close

    ' close the device manager
    VSTwain1.DeviceManager_Close

    ' enable application UI
    scanImagesButton.Enabled = True
The help is unfortunately not very helpful either, as it is written for .Net only and some functions (e.g. AddHandler) do not work in VB6.

I don't want to rewrite the old VB6 application completely, because it should only be extended by the scan function...

Furthermore, there are some other problems with the scanning.

The image when scanning in grayscale is displayed totally distorted and broken into stripes!? See screenshot.
https://share-your-photo.com/46e654ba50
Scanner : Brother MFC-2710DN
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Set scan area

Post by Alex »

Hello,

Thank you for the code snippet.

How do you set unit of measure in your code? I cannot find line "VSTwain1.Device_UnitOfMeasure = UNITOFMEASURE.UNITOFMEASURE_Millimeters".

Please see example here: https://www.vintasoft.com/docs/vstwain/ ... ution.html

Best regards, Alexander
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Set scan area

Post by Alex »

Hello Andreas,

Have you solved the problem?

Best regards, Alexander
Post Reply