本文介绍了Android的 - 降低位图资源的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的地图显示了Gowalla的位置。我使用ItemizedOverlay用一个简单的默认标记,但随着项目被绘制,我交换默认标记出与该地点的图标从Gowalla的下载在磁盘上9and缓存)。

I have a map in my application that shows locations from Gowalla. I use an ItemizedOverlay with a simple default marker, but as the items are drawn, I swap the default marker out with the location's icon downloaded 9and cached on disk) from Gowalla.

的问题是,如果有在屏幕上有很多的位置(例如30),所述位图的存储器中的大小是足够的崩溃的活性。以prevent这一点,我只保留SoftReferences的位图。不幸的是,这意味着位置将默认标记与图标之间闪烁(即,图标被加载,但然后有存储器pressure,所以他们中删除,但随后重新加载,因为它们是在屏幕上... )。

The problem is that if there are a lot of locations on screen (say 30), the size of the bitmaps in memory is enough to crash the activity. To prevent this, I only keep SoftReferences to the bitmaps. Unfortunately, this means that locations will flicker between the default marker and the icon (i.e., icons are loaded, but then there is memory pressure, so they're removed, but then reloaded because they're on screen...).

当我从Gowalla的下载图像,我已经扩展下来根据屏幕尺寸(48×48的华电国际,因此32×32的MDPI等),所以这些都不是庞大的图像,但我仍然强迫之间可能崩溃我的应用程序或具有图标闪烁和退出选择。是否有一些其他的方式,我可以减少内存位​​图使用?

When I download the images from Gowalla, I'm already scaling them down based on the screen size (48x48 for HDPI, so 32x32 for MDPI, etc.), so these aren't huge images, but I'm still forced to choose between potentially crashing my app or having the icons flicker in and out. Is there some other way I can reduce the memory that a Bitmap uses?

推荐答案

这将永远是一个问题,很遗憾。您可以尝试下采样。 Android:奇怪的内存不足问题

This will always be a problem unfortunately. You can try downsampling. Android: Strange out of memory issue

您可以尝试将图像保存到临时文件系统,使您不必每次都打网络。这应该有很大的帮助,或者甚至100%的闪烁。夫妇,与基于接入的堆缓存(如果你觉得到构建一个),而你可能是好的。

You might try saving the images to a temporary file system so that you don't have to hit the web every time. That should help a lot or maybe even 100% with the flicker. Couple that with an access-based heap cache (if you feel up to building one), and you're probably good.

这篇关于Android的 - 降低位图资源的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:36
查看更多