简体   繁体   中英

How can I make a loop to generate images infinite time to make a movie clip?

I have a question about how can I make a loop that runs a piece of code infinite time? Basically I have a peace of code that uses random function to create a pixelate bitmap image and display it to my image box to the user interface. However I am having difficulty when I need to execute that piece of code in order to generate images simultaneously and continually to be played after each other in order to make a video clip of those images. I have used “while (true)” loop but it doesn't show anything on my screen and my programme just crashes each time I run the code. Can anyone tell me how can I make a very smooth loop which executes my code in millisecond interval?

While (true)
{
    foreach (Point p in blackPixels)
    {
       if (r.NextDouble() < 0.20)
       {
           bmp.SetPixel(p.X, p.Y, Color.Black);
       }
       else
       {
           bmp.SetPixel(p.X, p.Y, Color.White);
       }
    }

    pictureBox1.Image = bmp;
}

If you are running this code on the UI thread, nothing will be displayed because your while loop blocks the thread. You will need to place your code in a separate thread or task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM