图像批量导出,一般导出都是会覆盖,要想不被覆盖,需要更新导出的文件名称。
代码如下:
Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
saveFileDialog.DefaultExt = "jpg";
saveFileDialog.Filter = "(*.jpg)|*.jpg|所有文件(*.*)|*.*”";
saveFileDialog.RestoreDirectory = true;
saveFileDialog.CreatePrompt = false;
saveFileDialog.ShowDialog();
string strFilePath = saveFileDialog.FileName;
if (!string.IsNullOrEmpty(strFilePath))
{
int k = 0;
for (int j = 0; j < _imageList.SelectedItems.Count; j++)
{
ImageListItem imgItem = (ImageListItem)_imageList.SelectedItem;
if (imgItem == null)
return;
BitmapImage img1 = imgItem.Image as BitmapImage;
if (img1.UriSource == null)
return;
if (k > 0)
{
strFilePath = strFilePath.Replace(".jpg","0"+ k + ".jpg");
}
string sourcefile = img1.UriSource.LocalPath;
if (!File.Exists(strFilePath))
System.IO.File.Copy(sourcefile, strFilePath, true);
k++;
}
}