我通过图片对话框处理图像但是 我得到例外
"用户名和密码不正确"
以下是我的代码
+DateUtils.HOUR_IN_MILLIS
如何在此提供用户名/密码?
答案 0 :(得分:0)
我假设您有一个按钮,可以在Click事件上打开Picture_OpenFileDialog。因此,您的代码必须如下所示:
Imports System.ComponentModel
Imports System.IO
Imports System.Globalization
Public Class Form1
Dim extn As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Picture_OpenFileDialog.ShowDialog()
End Sub
Private Sub Picture_OpenFileDialog_FileOk(sender As Object, e As CancelEventArgs) Handles Picture_OpenFileDialog.FileOk
If (CheckFileType(Picture_OpenFileDialog.FileName)) Then
'Make sure the directory you want to save to exist, otherwise you will get DirectoryNotFoundException
'If this is the same directory that your code is running, I suggest you do it this way:
Dim desiredplace As String = Directory.GetCurrentDirectory & "\SAP\Images\" & ExtractFilename(Picture_OpenFileDialog.FileName)
'If not, use your desiredplace
'Dim desiredplace As String = "\\SAP\Images\" & ExtractFilename(Picture_OpenFileDialog.FileName)
FileSystem.FileCopy(Picture_OpenFileDialog.FileName, desiredplace)
Else
MessageBox.Show("Please select a picture with a file format extension of either Bmp, Jpg, Jpeg, Gif or Png.", "invalid image", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
End Sub
Function CheckFileType(ByVal fileName As String) As Boolean
Dim ext As String = Path.GetExtension(fileName)
Select Case ext.ToLower()
Case ".gif"
extn = ".gif"
Return True
Case ".png"
extn = ".png"
Return True
Case ".jpg"
extn = ".jpg"
Return True
Case ".jpeg"
extn = ".jpeg"
Return True
Case ".bmp"
extn = ".bmp"
Return True
Case Else
Return False
End Select
End Function
Public Function ExtractFilename(filepath As String) As String
' If path ends with a "\", it's a path only so return String.Empty.
If filepath.Trim().EndsWith("\") Then Return String.Empty
' Determine where last backslash is.
Dim position As Integer = filepath.LastIndexOf("\"c)
' If there is no backslash, assume that this is a filename.
If position = -1 Then
' Determine whether file exists in the current directory.
If File.Exists(Environment.CurrentDirectory + Path.DirectorySeparatorChar + filepath) Then
Return filepath
Else
Return String.Empty
End If
Else
' Determine whether file exists using filepath.
If File.Exists(filepath) Then
' Return filename without file path.
Return filepath.Substring(position + 1)
Else
Return String.Empty
End If
End If
End Function
End Class