Skip to content

Instantly share code, notes, and snippets.

@msarchet
Created October 7, 2010 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msarchet/615737 to your computer and use it in GitHub Desktop.
Save msarchet/615737 to your computer and use it in GitHub Desktop.
Public Module scanning
Public Function scanImage() As Byte()
Dim fileScanned As Integer = 0
Dim filepath As String = String.Format("{0}\RXImage.png", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
EZTwain.SetAppTitle("Script Assist 9")
Call EZTwain.SetVendorKey("RS Software", -469019609)
Call EZTwain.SetHideUI(False)
Call EZTwain.SetFileAppendFlag(False)
Call EZTwain.SetMultiTransfer(False)
If EZTwain.OpenDefaultSource() Then
Call EZTwain.SetBlankPageMode(False)
fileScanned = EZTwain.AcquireToFilename(System.IntPtr.Zero, filepath)
If EZTwain.LastErrorCode <> 0 Then
If EZTwain.LastErrorCode = EZTwain.EZTEC_USER_CANCEL Then
Throw New Exception("Scan Was Cancelled")
End If
End If
End If
Call EZTwain.ReportLastError("While trying to scan")
Call EZTwain.CloseSource()
'EZTwain returns 0 on filescan success
If fileScanned = 0 Then
Try
Using fs As System.IO.FileStream = New System.IO.FileStream(filepath, IO.FileMode.Open, IO.FileAccess.Read)
Dim imagedata(fs.Length) As Byte
fs.Read(imagedata, 0, System.Convert.ToInt32(fs.Length))
fs.Close()
Return imagedata
End Using
Catch ex As Exception
DevExpress.XtraEditors.XtraMessageBox.Show("There was an error with converting the image for the database")
Clipboard.SetText(ex.ToString)
Return Nothing
End Try
Else
Return Nothing
End If
End Function
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment