8
Dim ImagePath As String = "images/spaceship2.png"
Dim img1 As Bitmap
Dim newImage As Image = Image.FromFile("images/spaceship2.png")

img1 = New Bitmap(ImagePath)
pb2.ImageLocation = ImagePath

pb1.Image = newImage

我想显示文件夹中的图像,例如,id 号为 22137471 的学生,名称为 22137471 的图片将显示在我的图片框上,在此之间,我在 google 某处看到了此代码。

4

2 回答 2

12

我想显示文件夹中的图像,例如,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
于 2013-11-03T02:06:44.897 回答
0

你可以试试这个:

PictureBox1.Image = Image.FromFile("c:\some path\folder\myImage.jpg")
于 2015-08-30T15:57:01.383 回答