如何显示保存在特定目录中的最新图像?
How can i display the latest image saved in a specific directory?
我正在使用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;
}
解决方法:
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;
}
我正在使用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;
}
解决方法:
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;
}