Android 使用inJustDecodeBounds=true解码位图会占用内存吗?
Im使用以下方法确定位图在内存中的大小: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;
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?您可以找到它:)尝试以下方法: