C# Windows Phone 8.1-尝试从相机卷获取缩略图时性能不佳

C# Windows Phone 8.1-尝试从相机卷获取缩略图时性能不佳,c#,windows-runtime,windows-phone,windows-phone-8.1,C#,Windows Runtime,Windows Phone,Windows Phone 8.1,我正在构建一个Windows Phone 8.1应用程序(Windows运行时,而不是Windows Phone Silverlight 8.1)。在我的应用程序中,我需要在GridView中显示CameraRoll的所有照片,但作为缩略图,以减少内存使用。当我尝试我的应用程序时,一切正常,但速度非常慢 我的代码如下: ===================== MainPage.xaml.cs============================= var files = await Kno

我正在构建一个Windows Phone 8.1应用程序(Windows运行时,而不是Windows Phone Silverlight 8.1)。在我的应用程序中,我需要在GridView中显示CameraRoll的所有照片,但作为缩略图,以减少内存使用。当我尝试我的应用程序时,一切正常,但速度非常慢

我的代码如下:

===================== MainPage.xaml.cs=============================
var files = await KnownFolders.CameraRoll.GetFilesAsync();
List<ImageSource> imageSources = new List<ImageSource>();

for(int i=0; i<files.Count; i++)
{
    await ExecuteCode(i, files, KnownFolders.CameraRoll, imageSources);
}

photosGrid.DataContext = imageSources;

private async Task ExecuteCode(int index, IReadOnlyList<StorageFile> files, StorageFolder folder, List<ImageSource> imageSources)
    {
        uint requestedSize = 90;

            using(StorageItemThumbnail itemThumbnail = await files[index].GetThumbnailAsync(ThumbnailMode.PicturesView, requestedSize))
            {
                using(IRandomAccessStream fStream = itemThumbnail.AsStreamForRead().AsRandomAccessStream())
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    await bitmapImage.SetSourceAsync(fStream);

                    imageSources.Add(bitmapImage);

                    bitmapImage = null;
                    GC.AddMemoryPressure((long)itemThumbnail.Size);
                }
            }
    }

========================MainPage.xaml==========================
<GridView x:Name="photosGrid" Height="392" Width="400" ItemsSource="{Binding}" Margin="0,0,-0.333,0" SelectionMode="Multiple" Background="Black">
                        <GridView.ItemTemplate>
                            <DataTemplate>
                                <Image Width="90" Height="90" Margin="5" Source="{Binding}" Stretch="UniformToFill"/>
                            </DataTemplate>
                        </GridView.ItemTemplate>

                        <GridView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsStackPanel />
                            </ItemsPanelTemplate>
                        </GridView.ItemsPanel>
                    </GridView>
=========================MainPage.xaml.cs=============================
var files=await KnownFolders.CameraRoll.getfileasync();
List imageSources=新列表();

对于(int i=0;iStorageFile.GetThumbnailAsync(ThumbnailMode)| GetThumbnailAsync(ThumbnailMode)方法

有人对此有答案吗?我也在尝试创建一个图库查看器,但如果我从文件夹中获取了100多张照片,应用程序会崩溃,并出现System.OutOfMemoryException。如果删除AddMemoryPressure调用,会发生什么情况。我不确定您是否需要这样做。AddMemoryPressure命令的文档说明您需要如果不需要,则会产生完全相同的压力。如果不需要,则会影响系统性能。直接从路径将图像加载到位图中如何?然后可以使用解码像素宽度和高度来约束图像。此外,如果用户只看到部分图像,则不要一次加载所有图像。尝试使用并行方法d、 看看这篇文章。