Android的快速载入位图位图、快速、Android

2023-09-05 00:24:35 作者:陪你洗澡

我有我想要加载我的屏幕上的图像块。所有的图像是我下载并存储在SD卡上的文件。

I have a block of images that I want to load on my screen. All the images are files that I downloaded and stored on SD-CARD.

到目前为止,我发现了两种方式来做到这一点,首先是加载它们在主线程,当活动开始,(我得到了约70图像,它需要我约2.1秒钟加载它们)。

So far I found two ways to do it, first is loading them on the main thread, when the activity is starting, (I got about 70 images and it takes me about 2.1 seconds to load them all).

另一种方法是什么,我的测试,现在。加载它们在独立的线程,所以同时我可以显示加载动画的用户。现在我implemintation与ThreadPoolExecutor花了4.3秒。我做了10个线程。

Another way is what I am testing right now. Load them on separated thread, so meanwhile I can show loading animation for the user. For now my implemintation with ThreadPoolExecutor took 4.3 sec. I did it on 10 threads.

和最后一个方法(这是我没有测试但唯一)正在与精灵表。

And the last method, (it's the only thing that I didn't test yet) is working with sprite sheet.

我不能使用应用程序缓存,因为在我的应用我有很多的屏幕,每个屏幕都有自己的图片集。

I can't use application cache because in my application I have lots of screens and each screen has its own images set.

你认为,什么是加载大量图像的最快方法,什么加速度工艺你知道,能帮帮我吗?

What do you think, what is the fastest way to load large amount of images and what acceleration technics do you know that can help me up?

推荐答案

一种选择是使用创建使用的WeakReference,使图像会从内存中取出时系统遇到内存不足的情况​​的图像缓存。这样就可以保留在内存中的图像,只需要从SD卡装载时,他们没有在内存中。所以,你当前活动将始终保持艰苦参照位的要求和图片缓存将保持弱引用位图的。

One option would be to use create image cache using the WeakReference so that the image would be removed from the memory when system encounter low memory situation. This way you can keep images in memory and only need load from sdcard when they are not in memory. So your current activity would always keep the hard reference to the bitmap's required and the image cache would keep the weak reference to the bitmap's.

以下是关于弱引用的一些详细信息:

Following is some more information about weak reference:

JavaDoc中的WeakReference

StackOverflow使用弱引用的缓存后讨论

 
精彩推荐
图片推荐