1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| Public Class Scanner
Declare Function TWAIN_AcquireToClipboard Lib "EZTW32.DLL" (ByVal hwndApp&, ByVal wPixTypes&) As Integer
Declare Function TWAIN_SetHideUI Lib "Eztw32.dll" Alias "TWAIN_SetHideUI" (ByVal ui As Long) As Long
Declare Function TWAIN_OpenDefaultSource Lib "Eztw32.DLL" Alias "TWAIN_OpenDefaultSource" (ByVal hwnd As Long) As Integer
Declare Function TWAIN_SetCurrentResolution Lib "Eztw32.dll" Alias "TWAIN_SetCurrentResolution" (ByVal neufdix As Double) As Long
Declare Function TWAIN_SetCurrentPixelType Lib "Eztw32.dll" Alias "TWAIN_SetCurrentPixelType" (ByVal deux As Long) As Long
Declare Function TWAIN_LoadSourceManager Lib "Eztw32.dll" Alias "TWAIN_LoadSourceManager" () As Long
Declare Function TWAIN_SetCurrentUnits Lib "Eztw32.dll" Alias "TWAIN_SetCurrentUnits" (ByVal zero As Long) As Long
Declare Function TWAIN_SetBitDepth Lib "Eztw32.dll" Alias "TWAIN_SetBitDepth" (ByVal zero As Long) As Long
Declare Function TWAIN_OpenSourceManager Lib "EZTW32.DLL" Alias "TWAIN_OpenSourceManager" (ByVal hwnd As Long) As Long
Declare Function TWAIN_CloseSource Lib "EZTW32.DLL" Alias "TWAIN_CloseSource" () As Long
Declare Function TWAIN_SelectImageSource Lib "EZTW32.DLL" Alias "TWAIN_SelectImageSource" (ByVal hwnd As Long) As Integer
Declare Function TWAIN_State Lib "EZTW32.DLL" Alias "TWAIN_State" () As Integer
Declare Function TWAIN_AcquireToFilename Lib "Eztwain3.dll" (ByVal hwndApp As Long, ByVal sFile As String) As Long
Declare Function TWAIN_SelectFeeder Lib "EZTW32.DLL" (ByVal fYes As Long) As Long
Declare Function TWAIN_SetCurrentResolution Lib "EZTW32.DLL" (ByVal nRes As Long) As Long
Declare Function TWAIN_LogFile Lib "EZTW32.DLL" (ByVal fLog As Long) As Long
Declare Function TWAIN_SetAutoScan Lib "EZTW32.DLL" (ByVal fYes As Long) As Long
Declare Function TWAIN_SetRegion Lib "EZTW32.DLL" (ByVal L As Double, ByVal T As Double, ByVal R As Double, ByVal B As Double) As Long
Declare Function TWAIN_AcquireMultipageFile Lib "EZTW32.DLL" (ByVal hwndApp As Long, ByVal FileName As String) As Long
Declare Function TWAIN_LastErrorCode Lib "EZTW32.DLL" () As Long
Declare Function TWAIN_ReportLastError Lib "EZTW32.DLL" (ByVal pzMsg As String) As Long
Declare Function TWAIN_GetCurrentResolution Lib "EZTW32.DLL" () As Long
Dim THdl As Integer = 0
Public Sub New(ByVal Hdl As Integer)
THdl = Hdl
End Sub
''' <summary>
''' récupération du résultat du scan
''' </summary>
Public Function Scan() As Drawing.Image
Dim Img As Drawing.Image = Nothing
Try
Dim Ret As Integer = 0
'Paramètre du Scan
If TWAIN_State() < 4 Then
MsgBox("Impossible de paramêtrer le scanner", MsgBoxStyle.Exclamation)
Else
'parametres du scanner
TWAIN_SetCurrentUnits(0) 'DPI
TWAIN_SetCurrentResolution(600) 'en points par pouces
TWAIN_SetCurrentPixelType(2) ' Scan format 0 = B&W, 1 Grey, 2 RGB
TWAIN_SetBitDepth(8) ' Bit Depth 1, 2, 4, 8 but depends on Pixeltype
TWAIN_SetHideUI(1)
End If
'scan du document
Ret = TWAIN_AcquireToClipboard(THdl, 32)
Img = CType(Clipboard.GetDataObject.GetData(System.Windows.Forms.DataFormats.Bitmap), Bitmap)
Catch ex As Exception
Img = Nothing
End Try
Return Img
End Function
Public Sub ChoixScan()
Try
Dim Ret As Integer = 0
'Fermeture de la source du scan
TWAIN_CloseSource()
TWAIN_LoadSourceManager()
TWAIN_OpenSourceManager(THdl)
Ret = TWAIN_SelectImageSource(THdl)
If Ret = 1 Then
Ret = TWAIN_OpenDefaultSource(THdl)
End If
If TWAIN_State() < 4 Then
MsgBox("Impossible de paramêtrer le scanner", MsgBoxStyle.Exclamation)
Else
'parametres du scanner
TWAIN_SetCurrentUnits(0) 'DPI
TWAIN_SetCurrentResolution(150) 'en points par pouces
TWAIN_SetCurrentPixelType(2) ' Scan format 0 = B&W, 1 Grey, 2 RGB
TWAIN_SetBitDepth(8) ' Bit Depth 1, 2, 4, 8 but depends on Pixeltype
TWAIN_SetHideUI(1)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub Test()
'************************************************
'TWAIN_SetContrast (8)
'TWAIN_SetBrightness (8)
'TWAIN_SetThreshold (8)
'TWAIN_SetGamma (8)
'TWAIN_SetShadow (8)
'TWAIN_SetHighlight (8)
'************************************************
Dim TypDoc As Integer = 0
TypDoc = 0 'Noir et Blanc
TypDoc = 1 'Nuance de gris
TypDoc = 2 'Couleur
Dim Bit As Integer = 0
Bit = 1 'Noir et Blanc
Bit = 8 'Nuance de gris
Bit = 8 'Couleur
Dim fileName As String
fileName = "D:\SCAN_DOC.pdf"
'TWAIN_LogFile(1)
TWAIN_SetHideUI(1) 'Cache l'interface utilisateur
If TWAIN_OpenDefaultSource(THdl) = 1 Then
'Call TWAIN_SelectFeeder(1)
Dim Ret As Integer = TWAIN_GetCurrentResolution
TWAIN_SetCurrentPixelType(TypDoc)
TWAIN_SetBitDepth(Bit)
TWAIN_SetCurrentResolution(Ret)
'Call TWAIN_SetAutoScan(1)
'Call TWAIN_SetRegion(0, 5, 3, 7)
TWAIN_AcquireToClipboard(THdl, 32)
'TWAIN_AcquireMultipageFile(THdl, fileName)
End If
'If TWAIN_LastErrorCode() <> 0 Then
' TWAIN_ReportLastError("Unable to scan.")
'End If
MsgBox("fin")
End Sub
End Class |
Partager