Created
October 7, 2010 19:37
-
-
Save msarchet/615737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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