How To Set Scanner Page Orientation from VB

  Imaging Toolkit

Question:

Please suggest the right way to know scanner supports the ICAP_ORIENTATION capabilty or not. And how to set the scanner page orientation

Answer:

This is a sample code snippet for get/set the ICAP_ORIENTATION capability of the scanner.

This code snippet is written in Visual Basic .NET 2005.

Available values of the ICAP_ORIENTATION are:

TWOR_ROT0 0

TWOR_ROT90 1

TWOR_ROT180 2

TWOR_ROT0270 3

TWOR_PORTRAIT = TWOR_ROT0

TWOR_LANDSCAPE=TWOR_ROT270

Private Sub BTNABOUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNABOUT.Click
Dim sValue As Short
Dim capID As Integer
Dim hData As Integer
Dim dData As Double
Dim i As Integer
Dim err As Integer

‘ Check the ICAP_ORIENTATION is supported or not
sValue = BiTwain.IsCapabilitySupported(BITWAINLib.enumCapabilities.ICAP_ORIENTATION)

If sValue = -1 Then
MessageBox.Show(“Error getting whether the capability is supported or not.”, “TWain Sample”, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
ElseIf sValue = 0 Then
MessageBox.Show(“The ICAP_ORIENTATION is not supported by the scanner.”, “TWain Sample”, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If

‘ Get available values for ICAP_ORIENTATION

‘ Get ID of the ICAP_ORIENTATION capability
capID = BiTwain.GetIDOfCapability(“ICAP_ORIENTATION”)
‘ The container type of ICAP_ORIENTATION is ENUMERATION
hData = BiTwain.GetCapabilityEnum(capID, BITWAINLib.enumCapabilityOperations.MSG_GET)

If BiTwain.ErrorCode = BITWAINLib.enumErrorCodes.TW_OK Then
‘ current value
dData = BiTwain.GetCurrentValueFromEnum(hData)
If BiTwain.ErrorCode <> BITWAINLib.enumErrorCodes.TW_GENERAL_ERROR Then
MessageBox.Show(“Current Value: ” + Convert.ToString(dData), “TWain Sample”, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(“Current Value: Invalid”, “TWain Sample”, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
‘ default value
dData = BiTwain.GetDefaultValueFromEnum(hData)
If BiTwain.ErrorCode <> BITWAINLib.enumErrorCodes.TW_GENERAL_ERROR Then
MessageBox.Show(“Default Value: ” + Convert.ToString(dData), “TWain Sample”, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(“Default Value: Invalid”, “TWain Sample”, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

‘ enumeration of the available values
For i = 0 To BiTwain.GetNumOfItemsInEnum(hData) – 1
dData = BiTwain.GetItemFromEnum(hData, i)
Next i
BiTwain.ReleaseData(hData)
Else
MessageBox.Show(“Getting operation of ICAP_ORIENTATION failed. Error: ” + BiTwain.GetErrorString(BiTwain.ErrorCode), “TWain Sample”, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If

‘ Try to set the orientation to TWOR_ROT90
err = BiTwain.SetCapabilityOneNumValue(capID, BITWAINLib.enumCapabilityOperations.MSG_SET, 1)

If err = BITWAINLib.enumErrorCodes.TW_OK Then
MessageBox.Show(“Setting of the ICAP_ORIENTATION is succeded.”, “TWain Sample”, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(“Setting operation of ICAP_ORIENTATION failed. Error: ” + BiTwain.GetErrorString(BiTwain.ErrorCode), “TWain Sample”, MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub

 
Regards,
Technical Support Team