我有这个listview和一个按钮。列表视图中还有几个图像。我想在按下按钮时从列表视图中保存图像。我不知道该怎么做。你能帮帮我吗?谢谢。这是我用于将图像插入列表视图的代码。
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();
}
答案 0 :(得分:2)
对于图像列表中的每个图像(imageList.Images),调用它(使用您自己提供的目录和文件名):
img.Save(@"C:\MyImage.jpg", ImageFormat.Jpeg);
答案 1 :(得分:1)
foreach (Image image in listView1.LargeImageList.Images)
{
string filename = ""; // make this whatever you need...
image.Save(filename);
}