我正在尝试获取一些图片并将其加载到ListView
作为图标,以便我可以选择其中的多个。我需要ImageList
ListView
,但我找不到为ImageList
的图片提供网址的方法,就像PictureBox
那样。
将这些图片读入ImageList
的最佳方式是什么?
答案 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);
}