我想显示文件夹中的图像,例如,id 为 22137471 的学生,名称为 22137471 的图片将显示在我的图片框上
尝试类似...
Dim id As String = "22137471"
Dim folder As String = "c:\some path\folder"
Dim filename As String = System.IO.Path.Combine(folder, id & ".png")
PictureBox1.Image = Image.FromFile(filename)
这是一个不锁定原始图像文件的更新版本:
Dim id As String = "22137471"
Dim folder As String = "c:\some path\folder"
Dim filename As String = System.IO.Path.Combine(folder, id & ".png")
Try
Using fs As New System.IO.FileStream(filename, IO.FileMode.Open)
PictureBox1.Image = New Bitmap(Image.FromStream(fs))
End Using
Catch ex As Exception
Dim msg As String = "Filename: " & filename &
Environment.NewLine & Environment.NewLine &
"Exception: " & ex.ToString
MessageBox.Show(msg, "Error Opening Image File")
End Try