Guest User

Untitled

a guest
Jun 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. Public Module scanning
  2. Public Function scanImage() As Byte()
  3. Dim fileScanned As Integer = 0
  4.  
  5. Dim filepath As String = String.Format("{0}\RXImage.png", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
  6. EZTwain.SetAppTitle("Script Assist 9")
  7. Call EZTwain.SetVendorKey("RS Software", -469019609)
  8. Call EZTwain.SetHideUI(False)
  9. Call EZTwain.SetFileAppendFlag(False)
  10. Call EZTwain.SetMultiTransfer(False)
  11. If EZTwain.OpenDefaultSource() Then
  12. Call EZTwain.SetBlankPageMode(False)
  13. fileScanned = EZTwain.AcquireToFilename(System.IntPtr.Zero, filepath)
  14. If EZTwain.LastErrorCode <> 0 Then
  15. If EZTwain.LastErrorCode = EZTwain.EZTEC_USER_CANCEL Then
  16. Throw New Exception("Scan Was Cancelled")
  17. End If
  18.  
  19. End If
  20. End If
  21. Call EZTwain.ReportLastError("While trying to scan")
  22.  
  23. Call EZTwain.CloseSource()
  24.  
  25. 'EZTwain returns 0 on filescan success
  26. If fileScanned = 0 Then
  27. Try
  28. Using fs As System.IO.FileStream = New System.IO.FileStream(filepath, IO.FileMode.Open, IO.FileAccess.Read)
  29. Dim imagedata(fs.Length) As Byte
  30. fs.Read(imagedata, 0, System.Convert.ToInt32(fs.Length))
  31. fs.Close()
  32. Return imagedata
  33. End Using
  34. Catch ex As Exception
  35. DevExpress.XtraEditors.XtraMessageBox.Show("There was an error with converting the image for the database")
  36. Clipboard.SetText(ex.ToString)
  37. Return Nothing
  38. End Try
  39. Else
  40. Return Nothing
  41. End If
  42.  
  43. End Function
  44. End Module
Add Comment
Please, Sign In to add comment