将图像加载到RAM中以备后用 [英] Load images in RAM for later use

查看:84
本文介绍了将图像加载到RAM中以备后用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

将图像加载到RAM中的最佳方法是什么,这样我就可以快速显示它们,而不会延迟加载图像.例如,当鼠标悬停在图像上方时,图像会发生变化,但是会有一个延迟,因为图像仍需要加载...
但是,制作10个MemoryStreams对我来说并不十分有趣...
有什么想法吗?

在此先感谢
MadMatt

Hello all,

What would be the best way to load images in RAM so I can show them quickly without having a delay when it loads the image. For example, an image changes when the mouse is over it, but there is a delay, because the image still needs to be loaded...
However, making 10 MemoryStreams doesn''t look very interesting to me...
Some ideas?

Thanks in advance
MadMatt

推荐答案

这很可能,但完全取决于要预加载图像的内存量以及在一定时间内需要它们的可能性.为什么需要保留十个内存流?您还可以在关闭所有流的情况下,使图像更靠近图像类,使其完全加载.但是,如果压缩了图像,则可能会占用更多的内存.

我会衡量时机,不要急于下结论.顺便说一下,由于JIT的原因,测量时序很重要.所有代码均按方法按需进行JIT编译.因此,在应用程序运行时开始时调用某些方法将比在以后再次调用它们花费更多的时间,因为在JIT上将花费大量时间.全面计划性能测量.

另外,我建议只有在您已经有问题或不舒服的延迟的情况下使用它.

—SA
It is quite possible but totally depends on how much memory you need for images you want to preload and how likely you need them during certain period of time. Why do you need to keep ten memory streams? You can also keep the the images closer to their, totally loaded, in the image class with all streams closed. It might take even more memory though, certainly if the image is compressed.

I would measure timing and not rush to conclusion. By the way, measuring timing is non-trivial because of JIT. All the code is JIT-compiled on demand on per-method basis. Therefore, calling some methods in the beginning of application run time will take a lot more time than calling them later again, as considerable amount of time will be spend on JIT. Plan your performance measurements thoroughly.

Also, I would recommend to go in for it only of you already have problematic or uncomfortable latency.

—SA


这篇关于将图像加载到RAM中以备后用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆