int countFiles = 0;
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile(ff[countFiles]);
countFiles++;
}
ff是一个包含40个文件的List。 定时器间隔设置为1000毫秒。
例外是在线:
pictureBox1.Image = Image.FromFile(ff[countFiles]);
System.OutOfMemoryException was unhandled
HResult=-2147024882
Message=Out of memory.
Source=System.Drawing
答案 0 :(得分:3)
你需要从内存中释放以前的图像试试这个:
private void timer1_Tick(object sender, EventArgs e)
{
if(pictureBox1.Image != null)
pictureBox1.Image.Dispose();
pictureBox1.Image = Image.FromFile(ff[countFiles]);
countFiles++;
}