有没有办法在线使用图像填充ImageList?

时间:2013-07-06 14:36:56

标签: c# .net winforms listview

我正在尝试获取一些图片并将其加载到ListView作为图标,以便我可以选择其中的多个。我需要ImageList ListView,但我找不到为ImageList的图片提供网址的方法,就像PictureBox那样。

将这些图片读入ImageList的最佳方式是什么?

1 个答案:

答案 0 :(得分:3)

你可以这样做(链接我随机选择一些汽车图片):

List<string> adress = new List<string>(){"http://www.diseno-art.com/news_content/wp-content/uploads/2012/09/2013-Jaguar-F-Type-1-600x399.jpg"
                                         ,"http://i.telegraph.co.uk/multimedia/archive/02351/Jaguar-F-type-9_2351861k.jpg",
                                          "http://i.telegraph.co.uk/multimedia/archive/02351/Jaguar-F-type-5_2351885k.jpg",
                                          "http://i.telegraph.co.uk/multimedia/archive/02351/Jaguar-F-type-7_2351893k.jpg"};
    ImageList il = new ImageList();
    foreach (string img in adress)
    {
          System.Net.WebRequest request = System.Net.WebRequest.Create(img);
          System.Net.WebResponse resp = request.GetResponse();
          System.IO.Stream respStream = resp.GetResponseStream();
          Bitmap bmp = new Bitmap(respStream);
          respStream.Dispose();

          il.Images.Add(bmp);
     }