dir*_*hem 7 memory android image bitmap virtual-machine
在我的应用用户中,选择图像和程序可让用户对图像进行更改.由于有很多不同的Android设备,我的程序在一些设备上崩溃,这些设备的堆大小较少.我想计算用户手机的最佳尺寸,以免因VM预算而崩溃.我添加了"Picsay Pro"的截图,这正是我正在寻找的东西.我知道"BitmapFactory.Options"我唯一的问题是找到一种方法来决定图像尺寸,这不会因为VM预算而导致应用程序崩溃.

AjO*_*ire 12
计算手机剩余的可用空间:
long freeMemory = (Runtime.getRuntime().maxMemory()) - (Debug.getNativeHeapAllocatedSize());
哪里,
Runtime.getRuntime().maxMemory() - 返回总堆限制大小(以字节为单位).
Debug.getNativeHeapAllocatedSize() - 返回应用程序已使用的数据量(以字节为单位).
通过此公式计算您正在使用的位图的大小,
long Bytes_allocated = (height of the Image) * (width of the Image) * 4;
比较freeMemory并Bytes_allocated选择适合您应用的大小.
| 归档时间: |
|
| 查看次数: |
1450 次 |
| 最近记录: |