Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用inJustDecodeBounds=true解码位图会占用内存吗?_Android_Bitmap - Fatal编程技术网

Android 使用inJustDecodeBounds=true解码位图会占用内存吗?

Android 使用inJustDecodeBounds=true解码位图会占用内存吗?,android,bitmap,Android,Bitmap,Im使用以下方法确定位图在内存中的大小: bitmapOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(imagePath, bitmapOptions); long bitmapSizeInMB = (bitmapOptions.outWidth * bitmapOptions.outHeight * 4) / 1048576L); bitmapOptions.inJustDecodeBounds = false;

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

bitmapOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagePath, bitmapOptions);
long bitmapSizeInMB = (bitmapOptions.outWidth *     bitmapOptions.outHeight * 4) / 1048576L);
bitmapOptions.inJustDecodeBounds = false;
例如,结果是5MB

但发生的是,当我使用

bitmap = BitmapFactory.decodeFile(imagePath, bitmapOptions);
将其设置为imageview,Logcat中的GC系统消息表示RAM使用量增加了20MB,而不是5 MB


因此,我的问题是,通过执行此位图大小检查操作,我是否增加了RAM使用率?

我认为ImageView会根据位图大小为图像分配RAM。无论位图是否已设置,由于您提供了尺寸随附的位图选项。

在imageview中设置图像之前或之后,ram使用率是否增加了?好的,但根据我所做的测量,分配的内存应该是5 MB,而不是20 MB?您可以找到它:)尝试以下方法: