private void btnGet_Click(object sender, EventArgs e)
{
string resultImg = "";
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
ofd.Filter = "*.jpg,*jpeg,*.bmp,*.gif,*.ico,*.tif|*.jpg;*jpeg;*.bmp;*.gif;*.ico;*.tif";
ofd.FilterIndex = 1;
ofd.RestoreDirectory = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
resultImg = ofd.FileName;
imageList1.ColorDepth = ColorDepth.Depth32Bit;
imageList1.ImageSize = new Size(255, 255);
imageList1.Images.Add(Image.FromFile(resultImg));
listView1.LargeImageList = imageList1;
//listView1.SmallImageList = imageList1;
//listView1.StateImageList = imageList1;
for (int i = 0; i < imageList1.Images.Count; ++i)
{
ListViewItem lvi = new ListViewItem();
lvi.ImageIndex = i;
listView1.Items.Add(lvi);
}
}
我这里出现的情况是找到并添加一幅图完全正确,当添加第二幅时,在Listview里是有三幅图,在添加时就报内存不足的错误
麻烦各位仁兄前来指教
{
string resultImg = "";
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
ofd.Filter = "*.jpg,*jpeg,*.bmp,*.gif,*.ico,*.tif|*.jpg;*jpeg;*.bmp;*.gif;*.ico;*.tif";
ofd.FilterIndex = 1;
ofd.RestoreDirectory = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
resultImg = ofd.FileName;
imageList1.ColorDepth = ColorDepth.Depth32Bit;
imageList1.ImageSize = new Size(255, 255);
imageList1.Images.Add(Image.FromFile(resultImg));
listView1.LargeImageList = imageList1;
//listView1.SmallImageList = imageList1;
//listView1.StateImageList = imageList1;
for (int i = 0; i < imageList1.Images.Count; ++i)
{
ListViewItem lvi = new ListViewItem();
lvi.ImageIndex = i;
listView1.Items.Add(lvi);
}
}
我这里出现的情况是找到并添加一幅图完全正确,当添加第二幅时,在Listview里是有三幅图,在添加时就报内存不足的错误
麻烦各位仁兄前来指教
是不是楼主把图片定义太大了,改为:
imageList1.ImageSize = new Size(16, 16);
试试
如果是,图标就是自动排列的,一行满了换下一行。