------ 文件大小转换工具
Formatter.formatFileSize(MainActivity.this, bitmap.getByteCount())
① 将字节byte转化为以B(字节)、KB、MB等为单位的数值,
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon, null);
Log.i(tag, "run: 原始bitmap filesize = " + Formatter.formatFileSize(MainActivity.this, bitmap.getByteCount()));
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 30;
final Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.icon, options);
String formatFileSize1 = Formatter.formatFileSize(MainActivity.this, bitmap1.getByteCount());
Log.i(tag, "run: options.inSampleSize = 1000 filesize = " + formatFileSize1);
04-01 01:44:34.640 2094-2107/? I/filesize: run: 原始bitmap filesize = 184KB
04-01 02:23:26.090 7052-7072/com.adnonstop.gaussianbg I/filesize: run: options.inSampleSize = 30 filesize = 144B
② Formatter.formatFileSize会根据文件字节数转化为合适的单位(B、KB、MB等数值)数值。