2013-03-10 73 views
0

我試圖做一個按鈕,它被按下後將得到一個目錄中的所有圖像,並將它們按順序放置在一個圖像數組中,我讓它工作到目前爲止它可以得到文件路徑,但我不能讓它工作的圖像,任何想法?使用getfile來定義初始化圖像數組的路徑

這裏是代碼我想要使用

private void button2_Click(object sender, RoutedEventArgs e) 
{ 
    string[] filePaths =Directory.GetFiles("C:/Users/Pictures/Movements/","*.jpg"); 
    System.Windows.Controls.Image[] Form_moves =new    System.Windows.Controls.Image[12]; 
    int i = 0; 

    foreach (string name in filePaths) 
    { 

     Console.WriteLine(name); 
     Form_moves[i] = filePaths[i] ; 
     i++; 

    } 

    string[] UserFilePaths = Directory.GetFiles("C:/Users/Pictures/Movements/User/", "*.jpg"); 

    foreach (string User_Move_name in filePaths) 
    { 
     Console.WriteLine(User_Move_name); 
    } 
} 
+0

定義「不能得到它工作圖像」 - 這是什麼意思,究竟? – Oded 2013-03-10 13:18:13

+0

這是用於WPF的? – 2013-03-10 13:22:12

+0

是它的wpf,我想要做的是使用獲取文件來獲取目錄中的所有文件,然後使用這些文件來填充圖像數組,但所有我見過的例子只使用「字符串」來獲取一個文件名的列表,我不能改變這個「圖像」 – H65 2013-03-10 13:32:10

回答

0

我想我已經解決了它:

private void button2_Click(object sender, RoutedEventArgs e) 
    { 
     string[] filePaths = Directory.GetFiles("C:/Users/Movements/Form/","*.jpg"); 
     string[] User_Moves_filePaths = Directory.GetFiles("C:/Users/Movements/User/", "*.jpg"); 
     System.Drawing.Image[] Form_Move = new System.Drawing.Image[9]; 
     System.Drawing.Image[] User_Move = new System.Drawing.Image[9]; 
     int i = 0; 
     int j = 0; 

     foreach (string name in filePaths) 
     { 
      Console.WriteLine(name);//Kept in for testing purposes SolidBrush Image CancelEventArgs see that array is being populated in correct order 
      Form_Move[i] = System.Drawing.Image.FromFile(filePaths[i]); 
      i++; 
     } 

     foreach (string User_Move_name in User_Moves_filePaths) 
     { 
      Console.WriteLine(User_Move_name); 
      User_Move[j] = System.Drawing.Image.FromFile(User_Moves_filePaths[j]); 
      j++; 
     } 
+0

現在得到這個錯誤:(最好的重載方法匹配'System.Drawing.Graphics.DrawImage(System.Drawing.Image,System.Drawing.Point [] ,System.Drawing.Rectangle,System.Drawing.GraphicsUnit,System.Drawing.Imaging.ImageAttributes,System.Drawing.Graphics.DrawImageAbort)'有一些無效的參數 – H65 2013-03-10 15:15:13