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

fer*_*ral 6 c# windows-phone windows-runtime windows-phone-8.1

我正在构建一个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>
Run Code Online (Sandbox Code Playgroud)

小智 0

StorageFile.GetThumbnailAsync(ThumbnailMode) | StorageFile.GetThumbnailAsync(ThumbnailMode) | getThumbnailAsync(ThumbnailMode) 方法 https://msdn.microsoft.com/en-us/library/windows/apps/br227212.aspx