2013-11-27 61 views
0

我試圖將我的圖像列表保存到用戶確定的文件夾中,在這種情況下,我有這個列表。如何將圖像列表保存到文件夾?

List<System.Drawing.Image> ListOfSystemDrawingImage = new List<System.Drawing.Image>(); 

     ListOfSystemDrawingImage.Add(MatrizWPF.Properties.Resources.Earth); 
     ListOfSystemDrawingImage.Add(MatrizWPF.Properties.Resources.Grass); 
     ListOfSystemDrawingImage.Add(MatrizWPF.Properties.Resources.Rabbit); 
     ListOfSystemDrawingImage.Add(MatrizWPF.Properties.Resources.Wolf); 

這裏地球,草,兔子和狼都是用同樣的方式叫做PNG圖像。

我的問題是,我怎樣才能保存我

List<System.Drawing.Image> listOfSystemDrawingImage = new List<System.Drawing.Image>(); 

由用戶確定的文件夾?

+0

如何獲取圖像名稱? WPF與System.Drawing.Image的 – Szymon

+0

? –

回答

1

可以使用System.Windows.Forms.FolderBrowserDialog爲用戶挑選的目標文件夾,並使用Image.Save將圖像保存在你的chioce格式

例子:

List<System.Drawing.Image> listOfSystemDrawingImage = new List<System.Drawing.Image>(); 

System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog(); 
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
{ 
    int index = 0; 
    foreach (var image in listOfSystemDrawingImage) 
    { 
     image.Save(string.Format("{0}\\Image{1}.png", dialog.SelectedPath, index), System.Drawing.Imaging.ImageFormat.Png); 
     index++; 
    } 
} 

不過,我不推薦使用WPF混合Window.Forms和System.Drawing,

0

如果您有名字,您可以將圖像轉換爲字節數組,然後使用File.WriteAllBytes。確保您傳遞的文件名爲WriteAllBytes的擴展名爲.png。這可能是一種更簡單的方法,但我並不像原始數據那樣處理媒體,所以這就是我想到的。

0

您可以保存的System.Drawing.Image名單是這樣的:

string folder = @"C:\temp"; 
int count = 1; 
foreach(Image image in listOfSystemDrawingImage) 
{ 
    string path = Path.Combine(folder, String.Format("image{0}.png", count)); 
    image.Save(path); 
    count++; 
} 

我不知道你在哪裏存儲圖像的名字,所以我只是叫他們image1.png,image2.png,等等。

相關問題