0
這段代碼從圖片庫中爲名稱face1.jpg,face2.jpg等拍照並顯示它們。現在的問題是,它適用於前9張圖片,然後停止。但它應該去通過所有的畫在畫廊c#如何從圖片庫,WP8.1加載圖片Silverlight
StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
IReadOnlyList<IStorageFile> file = await picturesFolder.GetFilesAsync(CommonFileQuery.OrderByDate);
string fname;
int picSize = 150;
int i = 0;
WriteableBitmap wv = new WriteableBitmap(picSize, picSize);
WriteableBitmap mypic = new WriteableBitmap(picSize, picSize);
if (file.Count > 0)
{
foreach (StorageFile f in file)
{
fname = "face" + i + ".jpg";
if (f.Name == fname)
{
i = i + 1;
ImageProperties properties = await f.Properties.GetImagePropertiesAsync();
WriteableBitmap wb = new WriteableBitmap((int)properties.Width, (int)properties.Height);
wb.SetSource((await f.OpenReadAsync()).AsStream());
reSize(wb, wv);
FilterWriteableBitmap(wv, mypic);
img.Source = mypic;
}
}
}
當我試圖拍照的時候我寫if(f.Name=="face10.jpg")
那麼它的工作原理,但它停止在face9內循環,直接的意思。
問題在於「假設該文件夾中有10個文件,foreach將經歷10次,但第一次它將查找face0.jpg並且只能訪問face9.jpg。」謝謝@Tim – Saira