Also PictureBox supports Animated Gifs and there's a class called ImageAnimator which could also be helpful - I am sure if you search on it you'll find examples.
Well, for animation purposes you generally don't want to go slower than 12 frames per second. Which just means you will show the 10 images, plus the next 2 every second. Or you can just change the delay value to 100 that I describe next.
Timers run off of milleseconds, so if you want to show 12 frames per second, you need to set your timer to 1000 / 12 = approx. 83 millisecond intervals.
If you want to just show 10 FPS, then set the timer to 100.
public class MyForm : Form { private const int Delay = 83; //Shows 12 FPS private System.Windows.Forms.Timer m_Timer = new System.Windows.Forms.Timer(); private int currentFrame = 0; private ImageList m_Images = new ImageList(); public MyForm() { m_Timer.Interval = Delay; m_Timer.Tick +=new EventHandler(OnTimerTick); m_Timer.Start();
//Set the current frame index to the next image for the next time you enter //this method. currentFrame = (currentFrame+1)%m_Images.Count;
//Draw the image to the graphics object next.
//THis is kinda tricky. You have to calculate how much time has //elapsed and compare that to the Delay. If we have exceeded the delay // then we just set the interval to 1 ms, which means to call again. // If we haven't used up the whole delay time, the we set the timer interval to the //amount of time that we haven't used for the current interval, before starting //the next. TimeSpan ts = DateTime.Now - now; m_Timer.Interval = Math.Max(1, Delay - ts.TotalMilliseconds ); m_Timer.Enabled = true; } }
Display of Sequence of Images in .Net after certain time Interval
hotfoot982
Aaron Schurg
Timers run off of milleseconds, so if you want to show 12 frames per second, you need to set your timer to 1000 / 12 = approx. 83 millisecond intervals.
If you want to just show 10 FPS, then set the timer to 100.
public class MyForm : Form
{
private const int Delay = 83; //Shows 12 FPS
private System.Windows.Forms.Timer m_Timer = new System.Windows.Forms.Timer();
private int currentFrame = 0;
private ImageList m_Images = new ImageList();
public MyForm()
{
m_Timer.Interval = Delay;
m_Timer.Tick +=new EventHandler(OnTimerTick);
m_Timer.Start();
//Load and add the images to the image list;
}
private void OnTimerTick(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
m_Timer.Stop();
Image toDisplay = m_Images.Images[currentFrame];
//Set the current frame index to the next image for the next time you enter
//this method.
currentFrame = (currentFrame+1)%m_Images.Count;
//Draw the image to the graphics object next.
//THis is kinda tricky. You have to calculate how much time has
//elapsed and compare that to the Delay. If we have exceeded the delay
// then we just set the interval to 1 ms, which means to call again.
// If we haven't used up the whole delay time, the we set the timer interval to the
//amount of time that we haven't used for the current interval, before starting
//the next.
TimeSpan ts = DateTime.Now - now;
m_Timer.Interval = Math.Max(1, Delay - ts.TotalMilliseconds );
m_Timer.Enabled = true;
}
}
Laquesis
I will try to implement it and let you know
If you have any other input please let me know
Thanks
Jyoti