0

I'm trying to make a button which upon being pressed will get all the images in a directory and place them in order in an array of images , I have it working so far where it can get the file paths but I cant get it working for images , any ideas ?

here is the code i'm trying to use

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);
    }
}
Oded
  • 489,969
  • 99
  • 883
  • 1,009
H65
  • 51
  • 1
  • 8
  • Define "cant get it working for images" - what does that mean, exactly? – Oded Mar 10 '13 at 13:18
  • yes its for wpf , What I'm trying to do is use get files to get all the files in the directory and then use these files to fill an image array however all the examples I've seen only use "string" to get a list of the file names and I cannot change this to "Image" – H65 Mar 10 '13 at 13:32

1 Answers1

0

I think I've solved it :

    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++;
        }
Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
H65
  • 51
  • 1
  • 8
  • now getting this error :( The best overloaded method match for 'System.Drawing.Graphics.DrawImage(System.Drawing.Image, System.Drawing.Point[],System.Drawing.Rectangle,System.Drawing.GraphicsUnit,System.Drawing.Imaging.ImageAttributes,System.Drawing.Graphics.DrawImageAbort)' has some invalid arguments – H65 Mar 10 '13 at 15:15