c# - How can I generate a random image using random function for infinite time? -


I am writing a code that creates a bitmap image using random pixels Want to play randomly generated images after each other on a display such as a movie clip .
I basically thought that a loop is my function every time and produces a new image and then display it for my image box and this process infinite time .

  while (right) {foreach (Point P in blackPixels) {if (r.NextDouble () of <0.20) {bmp.SetPixel (px, py, Color) .Black); } And {bmp.SetPixel (PX, P.Y, Color White); }} PictureBox1.Image = bmp; }  

My problem is that I have put the whole code in "while (true)", but this program crashed!
Can anyone tell me the correct way of playing with code that works fine for every frame and can display every frame consistently?

itemprop = "text">

You can try the following instead:

  Dispatcher Timer timer = new dispatch timer (); Timer.initval = new timespan (0, 0, 16); Timer Tick ​​+ = representative {timer.Stop (); // foreach code here foreach (Point P in blackPixels) ... timer.start (); }; Timer.start ();  

It should update the image without hitting every 16 seconds GUI thread.

For accuracy, make sure that you stop the timer with the timer. Pause before closing the form.


Comments