简体   繁体   English

UWP中BitmapImage的Ram使用

[英]Ram usage of BitmapImage in UWP

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. 为了学习如何在C#和Visual Studio上进行开发,我制作了一个脱机UWP应用程序来读取存储在基于Windows的平板电脑中的Comic / Manga。
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. 主要步骤之一是在一集中获取每个图像的相对目录,并创建每个图像的BitmapImage并将其加载到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. 在最极端的情况下,我加载了124张图像(光盘上有50,1 Mb),它们使用了大约860 Mb的Ram,这似乎令人兴奋。 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? 有没有更好的方法(使用更少的内存)来加载图像?

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. 如果要查看磁盘上所有图像的预览,一个很好的方法是调整内存中图像的大小,例如如何在Windows 10 UWP中复制和调整图像大小 ,然后按需加载完整图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM