c#如何从图片库加载图片,WP8.1 Silverlight

本文关键字:WP8 Silverlight 加载 图片库 | 更新日期: 2023-09-27 17:50:24

此代码从图片库中获取名称为face1.jpg, face2.jpg等的照片并显示它们。现在的问题是,它对前9张图片有效,然后就停止了。但是它应该浏览图库中的所有图片

 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

c#如何从图片库加载图片,WP8.1 Silverlight

变化

int i = 0;

int i = 1;

假设该文件夹中有10个文件,foreach将遍历10次,但第一次它将查找face0.jpg,并且只查找face9.jpg。