2012-05-05 61 views

回答

1
Directory.GetFiles(@"c:\images", ". jpg") 
+3

包含* only *「magic」代碼的答案沒有用處。 –

+1

我可以看到這個問題非常簡單,因此不需要太多解釋。 – Ahatius

+0

好的...你沒有。 「很多」與「無」不同。這個代碼*做什麼*?它如何解決他的問題? –

4

,使圖像的擴展名列表:

public static readonly List<string> ImageExtensions = new List<string> { 
    ".jpg", 
    ".jpe", 
    ".bmp", 
    ".gif", 
    ".png" 
}; 

爲了讓您的圖像列表,你可以通過文件夾中的文件迭代區分他們根據自己的擴展:

string YourDir = "Images\\"; 
List<Image> MyImgList = new List<Image>(); 
string[] images = System.IO.Directory.GetFiles(YourDir); 
images = images.Where(F => ImageExtensions.Contains(System.IO.Path.GetExtension(F))).ToArray(); 

foreach (string Img in images) { 
    BitmapImage bmp = new BitmapImage(); 
    bmp.BeginInit(); 
    bmp.UriSource = new Uri(Img, UriKind.Relative); 
    bmp.EndInit(); 
    MyImgList.Add(new Image { Source = bmp }); 
} 
+0

它是有道理的使用wpf可觀察集合? – GorillaApe

相關問題