【发布时间】:2014-10-23 20:37:49
【问题描述】:
所以我希望能够根据图像文件路径列表填充 1000 个缩略图。我尝试使用以下代码,但我意识到在 200 多张图像之后,我的程序会抛出“System.Drawing.dll 中发生‘System.OutOfMemoryException’类型的第一次机会异常”。
private void PopulateThumbnails(List<string> queryResults)
{
this.playerListView.Items.Clear();
this.imageList1.Images.Clear();
ImageViewer imageViewer = new ImageViewer();
foreach (string file in queryResults)
{
try
this.imageList1.Images.Add(Image.FromFile(file));
catch
Console.WriteLine("This is not an image file");
}
this.ListView.View = View.LargeIcon;
this.imageList1.ImageSize = new Size(256, 144);
this.ListView.LargeImageList = this.imageList1;
for (int j = 0; j < this.imageList1.Images.Count; j++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
this.ListView.Items.Add(item);
}
}
我意识到我应该只根据需要填充缩略图,但是...... a) 我如何知道列表视图中正在加载多少项目? b) 如何检测列表视图中的滚动事件?
【问题讨论】:
-
在 Google 上搜索如何将缩略图或图像添加到 ListViewItem 这里是以前的
SO在此期间发布stackoverflow.com/questions/17151776/… -
我的问题是不知道如何添加缩略图。它按原样工作。当我添加太多缩略图时会出现问题。
-
如何调试代码也许还有其他你不知道的事情发生..也许你需要在将项目添加到 ListView.Items @987654324 后释放这一行中的项目@ 但我敢打赌,一旦你通过代码,你可能会发现一些东西
-
我确实调试了代码......它卡在这一行“this.imageList1.Images.Add(Image.FromFile(file));”如果我添加到许多缩略图。如果我将列表减少到 100 则一切正常。问题是它的内存不足。这就是为什么我尽量不把它们都画出来。
-
this.ListView.View = View.LargeIcon;您是否认为图像的大小也可能导致问题..您是否考虑过重新调整 ImageSize 的大小...??
标签: c# winforms listview imagelist