Reputation: 21
In order to learn how develop on C# and Visual Studio i made an offline UWP application to read Comic/Manga stored in my Windows-based tablet.
One of the main steps was take the relative directory of each image in one episode and create a BitmapImage of eachone to load them to the FLipView.
Currently i'm doing it this way:
foreach (String value in ImageDirectory)
{
StorageFile file = await StorageFile.GetFileFromPathAsync((value));
IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
image = new BitmapImage();
await image.SetSourceAsync(fileStream);
images.Add(image); //images is a <List> of BitmapImage
}
In the most extreme case i have, with 124 images (50,1 Mb on disc) when loaded they use about 860 Mb of Ram which seems excesive. I know that load all the images as one is not the most efficent approach, where a more on-demad solution would be better, but finally my questions is:
Is there a better (that uses less ram) way to load the images?
Upvotes: 0
Views: 579
Reputation: 152
You have to have in mind that images loaded in memory are not compressed like on your disk. They are handled as bitmaps (uncompressed)
if you want to see a preview from all images on your disk, a good approach is to resize your images in memory, like in How to Copy and Resize Image in Windows 10 UWP, and load the full image on demand.
Upvotes: 1