下载图像缩略图并在 ListView C# 中显示它们
Download image thumbnails and show them in ListView C#
我正在尝试下载缩略图并在列表视图中显示它们。我做错了什么?
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);
你可以试试下面的代码。
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吗
我正在尝试下载缩略图并在列表视图中显示它们。我做错了什么?
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);
你可以试试下面的代码。
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吗