0

我想知道在 Android 中哪个是存储位图的数组实现的最佳选择。存储位图是个好主意ArrayList<Bitmap>还是不是一个好的解决方案。

我试图在我的应用程序中存储以编程方式创建的 5 个不同的位图并将它们存储在数组中,它们将它们绘制到 e 画布上,但它无法正常工作。

这是我正在做的事情:

//beginning
ArrayList<Bitmap> temp = new ArrayList<Bitmap>();

//in some function where mBitmap is been created
temp.add(mBitmap);

//in my custom class which extends View
Bitmap bm = Bitmap.createBitmap(temp.get(temp.size()-1));
mCanvas.drawBitmap(bm);
invalidate();

但是来自 temp 的位图从未添加到我的mCanvas.

任何想法为什么以及在Android / Java中将位图存储在Array中的最佳方式是什么?

4

2 回答 2

1

更好地使用LruCache进行位图缓存。请阅读有效地显示位图

于 2012-05-15T12:47:43.830 回答
0

这不是在 ArrayList 中存储位图的最佳方式,使用 LruCache 和软引用

 LruCache<String, SoftReference<Bitmap>> cache;
 cache = new LruCache<String, SoftReference<Bitmap>>(8*1024*1024) 
于 2014-06-17T09:44:40.497 回答