使用图像创建日期标准显示文件夹中的图像数据?

Displaying image data from folder using Image Created Date criteria?

我有两个用于显示文件夹中图像的控件,它们是:ImageListListView

现在我可以不用任何条件简单地使用上述控件来显示图像。

根据图像创建日期显示图像。为此,我有一个 DateTimePicker 控件来 select 日期,一个 ComboBox 到 select 一个选项和一个 Button 来显示结果,如以下快照。

For Example: Show image before the date 15/1/2015, date from the image tag.

这是我用来在 ListView 中显示图像的代码

   private void btn_Show_Click(object sender, EventArgs e)
   {

          lstView_un.Items.Clear();

          DirectoryInfo dir = new DirectoryInfo(@"D:\Images");
          foreach (FileInfo file in dir.GetFiles())
          {
              try
              {
                 this.imageList1.Images.Add(Image.FromFile(file.FullName));
              }
              catch
              {
                 Console.WriteLine("This is not an image");
              }
          }

   this.imageList1.ImageSize = new Size(256, 250);
   this.lstView_un.LargeImageList = this.imageList1;
   for (int j = 0; j < this.imageList1.Images.Count; j++)
   {
          ListViewItem item = new ListViewItem();
          item.ImageIndex = j;
          this.lstView_un.Items.Add(item);
   }             

}

玩这个:

var allfiles = Directory.GetFiles(yoursearchparams..);
files = new List<FileInfo>();
foreach(string f in projects) files.Add(new FileInfo(f));
var filesSorted = files.OrderByDescending(x=>x.CreationTime);

这是降序使用创建日期。还有 OrderByLastWriteTime.

这是完整的示例,包括:设置颜色深度、文本和多个扩展名以及使用日期来限制结果..

    private void button1_Click(object sender, EventArgs e)
    {   // last 2 weeks only:
        DateTime dt = DateTime.Now.AddDays(-14);  // use your own way to set it!

        string imagesPath = @"D:\scrape\SOusers";
        string[] extensions = new[] { ".jpg", ".jpeg", ".png" };
        var allfiles = Directory.GetFiles(imagesPath);
        List<FileInfo> files = new List<FileInfo>();
        foreach(string f in allfiles) files.Add(new FileInfo(f));
        var filesSorted = files.Where(f => extensions.Contains( f.Extension.ToLower()))
                               .Where(f => f.CreationTime < dt)
                               .OrderByDescending(f => f.CreationTime);
        this.imageList1.ImageSize = new Size(256, 250);
        this.imageList1.ColorDepth = ColorDepth.Depth32Bit;
        foreach (FileInfo fileInfo in filesSorted)
        {
            try {
                  this.imageList1.Images.Add(fileInfo.Name,
                                           Image.FromFile(fileInfo.FullName));
            }
            catch {
                    Console.WriteLine(fileInfo.FullName + "  is is not a valid image.");
            }
        }
        lstView_un.View = View.LargeIcon;
        lstView_un.LargeImageList = this.imageList1;
        lstView_un.Items.Clear();
        for (int j = 0; j < this.imageList1.Images.Count; j++)
        {
            ListViewItem item = new ListViewItem();
            item.ImageIndex = j;
            item.Text = imageList1.Images.Keys[j].ToString();
            this.lstView_un.Items.Add(item);
        }             
   }