如何在Android中获取位图的VM预算?

时间:2013-07-09 02:17:50

标签: java android bitmap out-of-memory

有没有办法找到位图的VM预算?

我的应用程序同时显示两张照片,这可以通过适当的缩放和颜色深度来实现,但是,如果设备具有更大的VM预算(就像有些人那样),我希望应用程序使用它来获得更好的图像质量。是否有API调用来获取VM预算?

我使用二进制试验和错误完成了这项工作,但速度很慢。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

您可以使用ActivityManager.getMemoryClass()获取每个进程允许的内存量,然后扣除代码所需的估计最大内存量,其余的可用于显示图像。

答案 1 :(得分:1)

我认为您可以尝试运行时类。

Runtime rt = getRuntime();
rt.totalMemory(); //Returns the total amount of memory which is available to the running program.

参考http://developer.android.com/reference/java/lang/Runtime.html