我使用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;
}
答案 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;
}