int z = 0;
foreach (FileInfo file in Variables.dir.GetFiles())
{
try
{
this.myImageList.Images.Add(Image.FromFile(file.FullName));
names[z] = file.FullName;
}
catch
{
Console.WriteLine("This is not an image file");
}
z++;
}
因此,例如,我的图像路径为“ D:\ ...”。 file.FullName是此路径,但有时当我将该路径放入数组时,该元素为null,但我不知道为什么。让我们...
try{ ... }
catch(Exception ex)
{
Console.WriteLine("This is not an image file: \n" + ex);
}
为了至少获得适当的错误以进一步调试