带图像的Foreach循环 [英] Foreach loop with images

查看:121
本文介绍了带图像的Foreach循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个80 PNG图像序列,正在尝试为Windows应用程序创建动画.文件路径为Assets/Star/,我试图弄清楚如何对文件夹中的每个图像进行foreach循环,因此它将图像对象设置为Image1,然后在经过一定的滴答声之后将其设置为Image1.将其更改为Image2,依此类推,这是我到目前为止的内容:

I have an 80 PNG image sequence in which I am trying to create an animation for my windows app. The file path is Assets/Star/ and I am trying to figure out how I would make a foreach loop for each image in the folder, so it would set the image object as Image1 then after a certain amount of ticks with the timer it would change it to Image2 and so on, here is what I have so far:

private void SubmitButton_Click(object sender, RoutedEventArgs e)
   {
      if(LevelUp == true)
        {
            string ImagePath = "Assets/Star/";
            foreach (Image item in ImagePath)
            {

            }
        }
   }

但是我认为我无法正确处理它,有人知道我应该如何处理吗?

However I dont think im approaching it correctly, does anyone know how i should approach this?

推荐答案

只需await Task.Delay异步等待设置的时间跨度即可:

Just await Task.Delay to asynchronously wait for a set span of time:

private async void SubmitButton_Click(object sender, RoutedEventArgs e)
{
    if (LevelUp)
    {
        string imagePath = "Assets/Star/";
        foreach (Image image in GetImages(imagePath))
        {
            ShowImage(image);
            await Task.Delay(timeToWait);
        }
    }
}

这篇关于带图像的Foreach循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆