如何在pictureBox1中显示每个新图像?

时间:2014-06-19 16:45:53

标签: c# .net winforms

在form1中我有一个计时器刻度事件,我将屏幕截图保存到硬盘:

private void timer1_Tick(object sender, EventArgs e)
        {
            count++;
            sc.CaptureScreenToFile(mainDirectory + count.ToString("D6") + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            sc.CaptureScreen();
            label2.Text = count.ToString();
            if (count == 1)
            {
                label4.Text = string.Format("{0:N2} KB", GetFileSizeOnDisk(mainDirectory + "000001.jpg").ToString());
                label4.Visible = true;
            }           
        }
        DisplayImages();

每次将新屏幕截图保存到硬盘后,我都希望在pictureBox1中显示此图像。 然后是下一个...定时器间隔设置为1000ms。因此,pictureBox1中的屏幕截图应该每秒更改一次。

private void DisplayImages()
        {

        }

如何在硬盘上获取文件的每一秒并将其显示在pictureBox中?并确保文件在使用时不重要。

例如,硬盘上的第一个文件是:000001.jpg然后是000002.jpg等等。

1 个答案:

答案 0 :(得分:0)

private void timer1_Tick(object sender, EventArgs e)
{
      count++;
      string fileName = mainDirectory + count.ToString("D6") + ".jpg";
      sc.CaptureScreenToFile(fileName , System.Drawing.Imaging.ImageFormat.Jpeg);
      sc.CaptureScreen();
      label2.Text = count.ToString();
      if (count == 1)
      {
          label4.Text = string.Format("{0:N2} KB", GetFileSizeOnDisk(fileName).ToString());
          label4.Visible = true;
      }    
      pictureBox1.ImageLocation =  fileName;   
}