0

我有一个包含 PictureBox 的数据转发器,并且需要从网络服务器获取图片。我已经有一个下载图像的功能,但绑定似乎不起作用。我对使用 Windows 窗体很陌生,我不太确定自己做错了什么。

我试过使用gridview,我可以确认它确实显示了图像。

Public Function DlImg(ByVal _URL As String) As Byte()
    Dim _tmpImage As Image = Nothing
    Dim BytesOut As Byte()
    Try
        Dim _HttpWebRequest As System.Net.HttpWebRequest = DirectCast(System.Net.HttpWebRequest.Create(_URL), System.Net.HttpWebRequest)
        _HttpWebRequest.AllowWriteStreamBuffering = True
        Dim _WebResponse As System.Net.WebResponse = _HttpWebRequest.GetResponse():
        Dim _WebStream As System.IO.Stream = _WebResponse.GetResponseStream()
        _tmpImage = Image.FromStream(_WebStream)
        _WebResponse.Close()
        Using picture As Image = _tmpImage
            Using stream As New IO.MemoryStream
                picture.Save(stream, Imaging.ImageFormat.Jpeg)
                BytesOut = stream.GetBuffer()
            End Using
        End Using
    Catch _Exception As Exception
        Return Nothing
    End Try

    Return BytesOut
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ListData.Columns.Add("Image", Type.GetType("System.Byte[]"))
    For Each row As DataRow In ListData.Rows
        row("Image") = DlImg("http://rental.joshblease.co.uk/propertyimages/p184js94kv1qco1e1e1jt71ouv11lm6.jpg")
    Next row
    ImgListItem.DataBindings.Add("Image", ListData, "Image", True)
    DataGridView1.DataSource = ListData
    DataRepeater1.DataSource = ListData
End Sub
4

0 回答 0