1

我有这个列表视图和一个按钮。列表视图中还有几个图像。当按下按钮时,我想从文件夹内的列表视图中保存图像。而且我不知道该怎么做。你能帮帮我吗?谢谢。这是我用来将图像插入列表视图的代码。

OpenFileDialog opend1 = new OpenFileDialog();

        opend1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";

        opend1.Multiselect = true;

        if (opend1.ShowDialog() == DialogResult.OK)
        {                

            listView1.View = View.LargeIcon;

            imageList.ImageSize = new Size(100, 100);

            for (int c = 0; c < opend1.FileNames.Length; c++)
            {
                Image i = Image.FromFile(opend1.FileNames[c].ToString());

                Image img = i.GetThumbnailImage(100, 100, null, new IntPtr());

                imageList.Images.Add(img);

            }

            listView1.LargeImageList = imageList;
            ListViewItem lstItem = new ListViewItem();
            lstItem.ImageIndex = imageList.Images.Count-1;
            listView1.Items.Add(lstItem);

            listView1.Refresh();

        }
4

2 回答 2

2

对于图像列表 (imageList.Images) 中的每个图像,调用它(使用您自己提供的目录和文件名):

img.Save(@"C:\MyImage.jpg", ImageFormat.Jpeg);
于 2012-11-15T04:27:06.910 回答
1
foreach (Image image in listView1.LargeImageList.Images)
{
    string filename = ""; // make this whatever you need...
    image.Save(filename);
}
于 2012-11-15T04:27:38.360 回答