Dynamsoft Home|Product Home

How to negotiate ICAP_FRAMES

The process of negotiating ICAP_FRAMES is the same as all the other capabilities. However, Frame has 4 data members: Left, Top, Right and Bottom, which can not be held in CapValue, CapValueString, CapItems or CapItemsString properties. Dynamic TWAIN provides several methods to deal with Frame: CapGetFrameLeft(), CapGetFrameTop(), CapGetFrameRight(), CapGetFrameBottom() and CapSetFrame().

For the general steps of capability negotiation, please refer to How to Negotiate Capability with Different Capability Container Types

The followings are the samples of ICAP_FRAMES negotiation:

Getting frame information;

Setting one frame;

Setting multiple frames.

Getting frame information

VB Sample:
    
    Dim lngIndex As Long
    Dim strFrame As String
    
    Twain.OpenSource
    
    Twain.Capability = ICAP_FRAMES
    
    If Twain.CapGet = False Then
        MsgBox "Failed." + vbCrLf + Twain.ErrorString, vbCritical + vbOKOnly
        Exit Sub
    End If
    
    If Twain.CapType = TWON_ONEVALUE Then
        strFrame = "Frame left: " + CStr(Twain.CapGetFrameLeft(0)) + vbCrLf
        strFrame = strFrame + "Frame top: " + CStr(Twain.CapGetFrameTop(0)) + vbCrLf
        strFrame = strFrame + "Frame right: " + CStr(Twain.CapGetFrameRight(0)) + vbCrLf
        strFrame = strFrame + "Frame bottom: " + CStr(Twain.CapGetFrameBottom(0))
        
        MsgBox strFrame
        
    ElseIf Twain.CapType = TWON_ENUMERATION Then
        For lngIndex = 0 To Twain.CapNumItems - 1
    
            strFrame = "Frame left: " + CStr(Twain.CapGetFrameLeft(lngIndex)) + vbCrLf
            strFrame = strFrame + "Frame top: " + CStr(Twain.CapGetFrameTop(lngIndex)) + vbCrLf
            strFrame = strFrame + "Frame right: " + CStr(Twain.CapGetFrameRight(lngIndex)) + vbCrLf
            strFrame = strFrame + "Frame bottom: " + CStr(Twain.CapGetFrameBottom(lngIndex))
            
            MsgBox strFrame
        
        Next lngIndex
    End If

Setting one frame

VB Sample:
    Twain.OpenSource
    
    Twain.Capability = ICAP_FRAMES
    Twain.CapType = TWON_ONEVALUE
    
    Twain.CapSetFrame 0, 0, 0, 5, 5
    
    If Twain.CapSet = True Then
        MsgBox "Successful."
    Else
        MsgBox "Failed." + vbCrLf + Twain.ErrorString, vbCritical + vbOKOnly
    End IfTwain.OpenSource
		

Setting multiple frames

VB Sample:
    Twain.OpenSource
    
    Twain.Capability = ICAP_FRAMES
    Twain.CapType = TWON_ENUMERATION

    Twain.CapNumItems = 2   ' 2 frames

    Twain.CapSetFrame 0, 0, 0, 5, 5
    Twain.CapSetFrame 1, 6, 6, 8, 8
        
    If Twain.CapSet = True Then
        MsgBox "Successful."
    Else
        MsgBox "Failed." + vbCrLf + Twain.ErrorString, vbCritical + vbOKOnly
    End If