如何处理winforms的ListView中的一千多个图像?

时间:2017-10-04 22:24:13

标签: c# winforms c#-4.0 bulk-load bulkloader

Hello StackOverFlow社区,

我正在尝试在listview中加载超过一千个图像但是我得到了OutOfMemoryException。我希望能够在用户向下滚动时加载图像,就像延迟加载体验一样。我怎样才能成功实现以下c#代码?

private void btnAddImg_Click(object sender, EventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Multiselect = true;
        DialogResult dr = ofd.ShowDialog();
        if(dr == DialogResult.OK)
        {


                foreach (string filename in ofd.FileNames)
                {
                    Image img = Image.FromFile(filename);
                    string a = c.ToString();


                    imageList1.Images.Add(a, img);

                    var listViewItem = listView1.Items.Add("");

                    listViewItem.ImageKey = a;

                    c++;
                }

        }
    }

0 个答案:

没有答案