如何使用VB将图像添加到图片框?

时间:2015-02-27 14:25:11

标签: wpf vb.net

我想创建一个图像查看器,将无限数量的图像加载到表单。有人可以帮我这个吗? 这是代码。 有一个名为loadImagesBttn的按钮和名为myImage

的图片框
Class MainWindow 

    Private Sub loadImagesBttn_Click(sender As Object, e As RoutedEventArgs) Handles loadImagesBttn.Click
        Dim dlg As New Microsoft.Win32.OpenFileDialog()
        dlg.FileName = "Image" 'Default image file name
        dlg.DefaultExt = ".jpg" 'Default extention 
        dlg.Filter = "Images (.jpg)| *.jpg " 'Filter images my extension

        'Show open file dialog box 
        Dim result? As Boolean = dlg.ShowDialog()

        'Process open file dialog box results 
        If result = True Then
            'Open image 
            Dim selectedImage As String = dlg.FileName

            myImage.Source = 'this is where I get confused.

        End If
    End Sub

End Class

1 个答案:

答案 0 :(得分:1)

您需要加载文件:

myImage.Source = New BitmapImage(New Uri(selectedImage))