下载图片缩略图并在ListView C#

时间:2017-11-09 15:30:19

标签: c# image listview thumbnails listviewitem

我试图下载缩略图并在列表视图中显示它们。我做错了什么?

ListView加载但它没有显示任何缩略图。

 using (var webClient = new WebClient())
        {
            foreach (var thumb in imgFiles.Item1)
            {
                byte[] data = webClient.DownloadData(thumb);
                using (MemoryStream imageData = new MemoryStream(data))
                {
                    Image img = Image.FromStream(imageData);
                    thumbList.Images.Add(img);
                }
            }
        }

 for (var i = 0; i < thumbList.Images.Count; i++)
        {
            ListViewItem lvi = new ListViewItem();
            lvi.ImageIndex = i;
            lvi.SubItems.Add("test");
            lvi.SubItems.Add("test1");

            lvi.Text = i.ToString();

            listViewLinks.Items.Add(lvi);
        }
        listViewLinks.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);

ListView loads without images

1 个答案:

答案 0 :(得分:0)

您可以尝试使用以下代码。

listView1.SmallImageList = thumblist;
ListViewItem lvi = new ListViewItem();
lvi.SubItems.Add("A");
lvi.SubItems.Add("B");
lvi.SubItems.Add("C");
lvi.ImageIndex = 2; // this will display YourImageList.Images[2] in the first column
listView1.Items.Add(lvi);

您是否能够获取ImageList。