0

我想,标题太具体了。所以,我想先解释一下,我想创建一个图章应用程序(如 photobox),我们可以在照片上放置很多图章图像,保存图像和设计。

我现在在我的代码中使用 option.inSampleSize。更有可能是这个链接:将图像加载到位图对象时出现奇怪的内存不足问题

当图像数量较小时,这解决了我的问题。但是当图像数量(图像计数)变得更大时,内存再次存在。

这里的专家有什么想法吗?目前我仍在使用 ImageView 来显示邮票图像。

或者..也许还没有解决方案?我唯一想到的就是限制图像的数量。

4

1 回答 1

0

您是否按照 Google 教程进行图像缓存?它概述了陷阱,并向您展示了如何正确缓存图像,以免超出内存预算。

Android 开发者:显示位图 - 缓存位图

关键线将是

// Get memory class of this device, exceeding this amount will throw an
// OutOfMemory exception.
final int memClass = ((ActivityManager) context.getSystemService(
        Context.ACTIVITY_SERVICE)).getMemoryClass();

// Use 1/8th of the available memory for this memory cache.
final int cacheSize = 1024 * 1024 * memClass / 8;

mMemoryCache = new LruCache(cacheSize) {
    @Override
    protected int sizeOf(String key, Bitmap bitmap) {
        // The cache size will be measured in bytes rather than number of items.
        return bitmap.getByteCount();
    }
};
于 2012-07-03T16:33:00.423 回答