2014-02-23 65 views
0

在我的應用程序中,我需要調用手機上Saved Pictures相冊的圖像,並檢索已保存的最新內容。我需要保證按日期收集最新的圖像。目前,我只是反轉收集和收集圖片,但是我意識到這實際上並不總是獲取最新的圖片,因爲它們按照名稱(從我所知道的)排列在PhotosHub的默認「保存的圖片」專輯中。我如何按日期抽取和分類這個集合,以便我能夠抽出最近的?如何按日期對PictureCollection進行排序

private PictureCollection _pictures = null; 

public void GetImages() 
{ 
    using (MediaLibrary library = new MediaLibrary()) 
    { 
     foreach (PictureAlbum album in library.RootPictureAlbum.Albums) 
     { 
      if (album.Name == "Saved Pictures") 
      { 
       _pictures = album.Pictures; 

       if(_pictures != null) 
       { 
        //search for the most recent pictures in the album 
        foreach (var p in _pictures.Reverse()) //need to sort by date first 
        { 
         //Do something with pictures 

        } 
       } 
      } 
     } 
    } 
} 

回答

0

我會去如下:

  1. 變化_pictures是的List<Picture>代替PictureCollection

  2. 變化GetImages方法:

    public void GetImages() 
    { 
        using (MediaLibrary library = new MediaLibrary()) 
        { 
         var savedPictures = library.RootPictureAlbum.Albums.First(a => a.Name == "Saved Pictures"); 
    
         _pictures = savedPictures.Pictures.OrderByDescending(p => p.Date).ToList(); 
        } 
    } 
    
相關問題