的Android内存不足错误 - 位图太大 [英] Android Out of Memory Error - Bitmap is too big
问题描述
在我的比赛,我有一个位图图像其功能是作为游戏背景(画布上绘制)。越大越空间有在游戏中用户的图象入住,所以我想将位图要尽可能大,而不会造成内存问题。
In my game, I have a bitmap image which functions as the games background (drawn on a canvas). The bigger the image the more "space" there is in the game for the user to move in, so I want the bitmap to be as big as possible without causing memory problems.
好吧,我摔过,并提请一个巨大的位图,这导致了内存不足的错误立即initialzation,所以我缩小了位图位。但我认为它太小了。我的问题是如何衡量所使用的内存的安全的限制?
Well I went overboard and drew an enormous bitmap, which caused an out of memory error immediately on initialzation, so I shrunk the bitmap a bit. But I think its too small. My question is how can I measure the "safe" limit of the memory being used?
我用下面的方法和阅读的目录下载输出:
I used the following methods and read the output in CatLog:
Debug.getNativeHeapAllocatedSize();
Log.v("MEMORY",String.valueOf(Debug.getNativeHeapAllocatedSize()) );
Log.v("FreeMEMORY",String.valueOf(Debug.getNativeHeapFreeSize ()) );
其中所述的结果是:
The results of which were:
05-25 09:53:54.044: VERBOSE/MEMORY(23044): 9715624
05-25 09:53:54.044: VERBOSE/FreeMEMORY(23044): 61528
的可用内存似乎比较小?此刀贴着骨头?
The free memory seems quite small? Is this cutting close to the bone?
推荐答案
如果您正在缩小位图,则也首先它被加载到内存中,并最终给你的错误。
If you are shrinking bitmap then also first it gets loaded into memory and eventually gives you error.
您需要使用的东西称为 BitmapFactory.Options
其中precalulates之前加载位图。
You need to use something called as BitmapFactory.Options
which precalulates before loading the bitmap.
这篇关于的Android内存不足错误 - 位图太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!