0

我正在尝试制作一个按钮,按下该按钮后将获取目录中的所有图像并将它们按顺序放置在图像数组中,到目前为止,它可以在可以获取文件路径的地方工作,但我无法让它工作对于图像,有什么想法吗?

这是我正在尝试使用的代码

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);
    }
}
4

1 回答 1

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++;
        }
于 2013-03-10T14:25:41.147 回答