Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自URL的VB.Net Imagelist列表视图_Vb.net_Image_Load_Imagelist - Fatal编程技术网

来自URL的VB.Net Imagelist列表视图

来自URL的VB.Net Imagelist列表视图,vb.net,image,load,imagelist,Vb.net,Image,Load,Imagelist,我有一个显示多个jpg图像的网站,我想从URl加载它们,并将它们显示在我的图像列表中 我可以通过使用以下代码在SSD上的图像执行此操作: Dim count as integer = 0 Dim imgs as ImageList = New ImageList() imgs.ImageSize = New Size(75, 75) Dim files as String() files = Directory.GetFiles("C:/image/folger") Li

我有一个显示多个jpg图像的网站,我想从URl加载它们,并将它们显示在我的图像列表中

我可以通过使用以下代码在SSD上的图像执行此操作:

Dim count as integer = 0
Dim imgs as ImageList = New ImageList()
imgs.ImageSize = New Size(75, 75)

Dim files as String()
files = Directory.GetFiles("C:/image/folger")

ListView.SmallImageList = imgs  

For each x in files
   imgs.Images.Add(Image.FromFile(f))
   ListView.Items.Add("Image Number: " & count, count)
Next
    //Loading the Image from URL into Memory as Bitmap fuirst
    Dim tClient As WebClient = New WebClient
    Dim tImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData("https://url.to.image/1.jpg"))) 

    //Applying the Bitmap from Memory into the ImageList
    Dim imgs As ImageList = New ImageList()
    imgs.ImageSize = New Size(50, 50)
    imgs.Images.Add(tImage)

    ListView1.SmallImageList = imgs
    ListView1.Items.Add("Image " & vbCrLf & count.ToString, count)
现在,我想实现同样的事情,但从一个URL没有下载文件到我的驱动程序第一。我使用以下代码完成了50%的操作:

Dim count as integer = 0
Dim imgs as ImageList = New ImageList()
imgs.ImageSize = New Size(75, 75)

Dim files as String()
files = Directory.GetFiles("C:/image/folger")

ListView.SmallImageList = imgs  

For each x in files
   imgs.Images.Add(Image.FromFile(f))
   ListView.Items.Add("Image Number: " & count, count)
Next
    //Loading the Image from URL into Memory as Bitmap fuirst
    Dim tClient As WebClient = New WebClient
    Dim tImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData("https://url.to.image/1.jpg"))) 

    //Applying the Bitmap from Memory into the ImageList
    Dim imgs As ImageList = New ImageList()
    imgs.ImageSize = New Size(50, 50)
    imgs.Images.Add(tImage)

    ListView1.SmallImageList = imgs
    ListView1.Items.Add("Image " & vbCrLf & count.ToString, count)

这非常有效,但正如您所看到的,缺少“每个循环”。我不知道如何请求或收集网站上的每张图片。因为所有的图片都是“x.jpg”,而x总是并且只是一个数字,所以我想在网站上搜索每个图片的源代码,直到没有图片为止。如果有人能帮我解决这个问题,那就太好了。

您可以下载照片,直到收到http错误404,这意味着地址不存在

Dim pictIndx As Integer = 0
Dim tClient As WebClient = New WebClient
Dim imgs As ImageList = New ImageList()

Try
   While True
       'Download until you get 404
       pictIndx += 1
       Dim tImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData("https://url.to.image/" & pictIndx & ".jpg"))) 
       'Download the image
       imgs.ImageSize = New Size(50, 50)
       imgs.Images.Add(tImage)
       'Add the image to the ListView
       ListView1.SmallImageList = imgs
       ListView1.Items.Add("Image " & vbCrLf & count.ToString, count)

   End While
Catch ex as Exception
 'You downloaded all the photos
End Try
如果这不起作用,请告诉我