使用 inJustDecodeBounds=true 解码位图是否占用内存



使用以下方法确定位图将在内存中占用的大小:

bitmapOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagePath, bitmapOptions);
long bitmapSizeInMB = (bitmapOptions.outWidth *     bitmapOptions.outHeight * 4) / 1048576L);
bitmapOptions.inJustDecodeBounds = false;

例如,结果是 5MB

但是发生的情况是,当我使用

bitmap = BitmapFactory.decodeFile(imagePath, bitmapOptions);

并将其设置为图像视图,Logcat 中的 GC 系统消息显示 RAM 使用量增加了 20 MB,而不是 5。

所以我的问题是,通过执行此位图大小检查操作,我会增加 RAM 使用率吗?

我认为 ImageView 根据位图大小为图像分配 ram。无论是否设置了位图,因为您提供了尺寸附带的位图选项。

最新更新