Private Sub btnScanPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScanPage.Click
btnScanPage.Text = "Scanning Page, Please wait..."
Me.Cursor = Cursors.WaitCursor
If scan() = True Then
btnScanPage.Text = "Scan Page"
UgcDetails.lstattach.Items.Add(fileName)
Me.Cursor = Cursors.Default
Me.Close()
Me.Dispose()
End If
End Sub
-------------------------------------------------------------------
--------------------------------Function scan-------------------
Private Function scan() As Boolean
Try
Dim commonDialogClass As New CommonDialogClass()
Dim scannerDevice As Device = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, False, False)
If scannerDevice IsNot Nothing Then
Dim scannnerItem As Item = scannerDevice.Items(1)
AdjustScannerSettings(scannnerItem, 100, 0, 0, 850, 1150, 0, 0)
Dim scanResult As Object = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatPNG, False)
If scanResult IsNot Nothing Then
Dim image As ImageFile = DirectCast(scanResult, ImageFile)
Dim path1 As String = "D:\scan\" & Me.Tag & "\"
My.Computer.FileSystem.CreateDirectory(path1)
fileName = path1 & Now.ToString.Replace("/", "").Replace("-", "").Replace(":", "") & ".jpg"
If SaveImageToFile(image, fileName) = True Then
PictureBox1.ImageLocation = fileName
Return True
End If
End If
End If
Catch ex As Exception
Return False
End Try
End Function
btnScanPage.Text = "Scanning Page, Please wait..."
Me.Cursor = Cursors.WaitCursor
If scan() = True Then
btnScanPage.Text = "Scan Page"
UgcDetails.lstattach.Items.Add(fileName)
Me.Cursor = Cursors.Default
Me.Close()
Me.Dispose()
End If
End Sub
-------------------------------------------------------------------
--------------------------------Function scan-------------------
Private Function scan() As Boolean
Try
Dim commonDialogClass As New CommonDialogClass()
Dim scannerDevice As Device = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, False, False)
If scannerDevice IsNot Nothing Then
Dim scannnerItem As Item = scannerDevice.Items(1)
AdjustScannerSettings(scannnerItem, 100, 0, 0, 850, 1150, 0, 0)
Dim scanResult As Object = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatPNG, False)
If scanResult IsNot Nothing Then
Dim image As ImageFile = DirectCast(scanResult, ImageFile)
Dim path1 As String = "D:\scan\" & Me.Tag & "\"
My.Computer.FileSystem.CreateDirectory(path1)
fileName = path1 & Now.ToString.Replace("/", "").Replace("-", "").Replace(":", "") & ".jpg"
If SaveImageToFile(image, fileName) = True Then
PictureBox1.ImageLocation = fileName
Return True
End If
End If
End If
Catch ex As Exception
Return False
End Try
End Function