Foreach loop with images

你说的曾经没有我的故事 提交于 2019-12-02 07:20:07

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/28464580/foreach-loop-with-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!