C# 使用getfile定义初始化图像数组的路径
我正在尝试制作一个按钮,当按下该按钮时,将获得目录中的所有图像,并将它们按顺序排列在一组图像中,我已经将其工作到目前为止,它可以获得文件路径,但我无法使其用于图像,有什么想法吗 这是我试图使用的代码C# 使用getfile定义初始化图像数组的路径,c#,arrays,image,getfiles,C#,Arrays,Image,Getfiles,我正在尝试制作一个按钮,当按下该按钮时,将获得目录中的所有图像,并将它们按顺序排列在一组图像中,我已经将其工作到目前为止,它可以获得文件路径,但我无法使其用于图像,有什么想法吗 这是我试图使用的代码 private void button2_Click(object sender, RoutedEventArgs e) { string[] filePaths =Directory.GetFiles("C:/Users/Pictures/Movements/","*.jpg");
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);
}
}
我想我已经解决了:
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++;
}
定义“无法使其用于图像”-这到底意味着什么?是的,对于wpf,我尝试使用get files获取目录中的所有文件,然后使用这些文件填充图像数组,但是我看到的所有示例仅使用“string”获取文件名列表,我无法将其更改为“image”现在出现此错误:(与“System.Drawing.Graphics.DrawImage(System.Drawing.Image,System.Drawing.Point[],System.Drawing.Rectangle,System.Drawing.GraphicsUnit,System.Drawing.ImageAttributes,System.DrawImageAbort)”匹配的最佳重载方法具有一些无效参数