DataGridView中的显示图像无法正常工作

时间:2014-12-31 13:24:50

标签: vb.net datagridview

我正在尝试在DataGridView控件中显示图像,我使用了这段代码:

     Dim img As Bitmap
    img = New Bitmap("http://cache.images.globalsportsmedia.com/soccer/teams/75x75/1241.png")
    ' Create the DGV with an Image column
    Dim dt As New DataGridView()
    Me.Controls.Add(dt)
    Dim imageCol As New DataGridViewImageColumn()
    dt.Columns.Add(imageCol)
    ' Add a row and set its value to the image
    dt.Rows.Add()
    dt.Rows(0).Cells(0).Value = img


但在这一行中有一个错误:img = New Bitmap("http://cache.images.globalsportsmedia.com/soccer/teams/75x75/1241.png") 编译器向我显示此消息:不支持URI格式。

我试图在网站上的图片表中显示,我该如何克服这个?

1 个答案:

答案 0 :(得分:0)

试试这个:

Dim request as WebRequest = WebRequest.Create("http://cache.images.globalsportsmedia.com/soccer/teams/75x75/1241.png")
Dim response = request.GetResponse()
Dim responseStream as Stream = response.GetResponseStream()
Dim bitmap2 as Bitmap = new Bitmap(responseStream)


' Create the DGV with an Image column
// proceed with your code.