如何显示保存在特定目录中的最新图像?

时间:2015-04-09 15:01:21

标签: c# .net winforms c#-4.0 picturebox

我使用Windows窗体显示图像,我需要显示保存在特定目录中的最新图像。任何想法,请。

我已经尝试过此代码,但是我们无法将信息文件转换为图像??

 private List<FileInfo> GetLastUpdatedFileInDirectory(DirectoryInfo directoryInfo)
    {
        FileInfo[] files = directoryInfo.GetFiles();
        List<FileInfo> lastUpdatedFile = new List<FileInfo>();
        DateTime lastUpdate = DateTime.MinValue;
        foreach (FileInfo file in files)
        {
            if (file.LastAccessTime > lastUpdate)
            {
                lastUpdatedFile.Add(file);
                lastUpdate = file.LastAccessTime;
            }
        }

        return lastUpdatedFile;
    }

1 个答案:

答案 0 :(得分:0)

解决方案:

 private void ImageForm_Load(object sender, EventArgs e)
        {
 var f1 = GetLatestWritenFileFileInDirectory(new DirectoryInfo(@"C:\Users\Public\Pictures\Sample Pictures"));
  pictureBox1.ImageLocation = f1.FullName;
}


     private List<FileInfo> GetLastUpdatedFileInDirectory(DirectoryInfo directoryInfo)
        {
            FileInfo[] files = directoryInfo.GetFiles();
            List<FileInfo> lastUpdatedFile = new List<FileInfo>();
            DateTime lastUpdate = DateTime.MinValue;
            foreach (FileInfo file in files)
            {
                if (file.LastAccessTime > lastUpdate)
                {
                    lastUpdatedFile.Add(file);
                    lastUpdate = file.LastAccessTime;
                }
            }

            return lastUpdatedFile;
        }