的Andr​​oid内存不足错误 - 位图太大 [英] Android Out of Memory Error - Bitmap is too big

查看:182
本文介绍了的Andr​​oid内存不足错误 - 位图太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的比赛,我有一个位图图像其功能是作为游戏背景(画布上绘制)。越大越空间有在游戏中用户的图象入住,所以我想将位图要尽可能大,而不会造成内存问题。

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.

参考,对这个问题的最大投票的答案。

这篇关于的Andr​​oid内存不足错误 - 位图太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆