我有一个包含 1000 张图像的文件夹,这些图像的图像名称顺序为“ICON000,ICON001 直到 ICON 999”。我需要它们以 5 秒的时间延迟顺序显示在我的 WPF 图像控件中。我使用文件对话框来获取特定文件夹的路径和图像的相应前缀(ICON)。我使用了下面的代码
string path = null;
string selected_file;
string URI;`enter code here`
openfile.AddExtension = true;
openfile.Filter = "GIF(*.gif)|*.gif|PNG(*.png)|*.png|JPG(*.jpg)|*.jpg|JPEG(*.jpeg)|*.jpeg";
DialogResult result = openfile.ShowDialog();
if (result.ToString() == "OK")
{
selected_file = openfile.FileName;
Uri uri_temp = new Uri(selected_file);
URI = uri_temp.AbsoluteUri;
string[] ext = URI.Split('.');
//textBox1.Text = ext[0];
string[] ss = ext[0].Split('/');
int a = ss.Length;
string a1 = ss[a - 1];
string image_prefix = a1.Substring(0, 4);
string image_no = a1.Substring(4, 3);
for (int i = 0; i < a-1; i++)
{
path = path + ss[i] + "/";
}
string path1 = path;
path = path1 + image_prefix + image_no + "." + ext[1];
for (int i = 1; i < 999; i++)
{
if (i < 10)
{
image_no = "00" + i;
}
else if (i < 100)
{
image_no = "0" + i;
}
else
{
image_no = i.ToString();
}
path = path1 + image_prefix + image_no + "." + ext[1];
string dasdasd = path;
string loc = new Uri(path).LocalPath;
bool asasa = File.Exists(loc);
if (asasa == true)
{ System.Threading.Thread.Sleep(5000);
image1.Source = new BitmapImage(new Uri(dasdasd));
}
else
{
System.Windows.Forms.MessageBox.Show("File not found");
}
但是图像没有显示出来。做需要的事情....!!