Windows Phone 8.1 - Poor performance when trying to get thumbnail images from Camera Roll

I am building a Windows Phone 8.1 application (Windows Runtime, not Windows Phone Silverlight 8.1). In my application, I need to display all the CameraRoll photos in a GridView, but in thumbnails to reduce memory usage. When I try to run my application, everything works fine, but it is TOO EXCELLENT.

My code is as follows:

===================== 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> 
+6
source share
1 answer

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

0
source

Source: https://habr.com/ru/post/981737/


All Articles