【问题标题】:Displaying image from folder/file in vb.net在 vb.net 中显示文件夹/文件中的图像
【发布时间】:2013-11-13 23:00:35
【问题描述】:
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 某处看到了此代码。

【问题讨论】:

    标签: vb.net-2010


    【解决方案1】:

    我想显示文件夹中的图像,例如,具有 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
    

    【讨论】:

    • Dim id As String = LinkLabel1.Text Dim folder As String = "d:\image\" Dim filename As String = System.IO.Path.Combine(folder, id & ".jpg") PictureBox1.Image = Image.FromFile(filename) '它不起作用,我将从datadisk d加载它,我的文件夹是image,里面是要显示的图片
    【解决方案2】:

    你可以试试这个:

    PictureBox1.Image = Image.FromFile("c:\some path\folder\myImage.jpg")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-26
      • 1970-01-01
      • 1970-01-01
      • 2011-09-11
      • 2012-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多