-------- 代码
<ImageView
android:id="@+id/iv_blur"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="center"
android:layout_weight="1" />
<ImageView
android:id="@+id/iv_blur2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="center" />
ImageView scaleType = “center” -展示原图,不压缩,不放大,仅仅展示原图而已
/**
* 压缩Bitmap
*
* @param imageView 展示原图
* @param imageViewBlur2 展示压缩后的bitmap
*/
private void createScaleDownBmp(ImageView imageView, ImageView imageViewBlur2) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tesla, null);
imageView.setImageBitmap(bitmap);
Bitmap scaledBitmap = bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / 10, bitmap.getHeight() / 10, true);
imageViewBlur2.setImageBitmap(scaledBitmap);
}
-- 压缩前后对比
------ 压缩前后Bitmap文件大小比较
04-01 08:07:40.179 14317-14317/com.xxx.gaussiantest I/filesize: createScaleDownBmp: Bitmap压缩前文件大小 = 3.15MB
04-01 08:07:40.179 14317-14317/com.xxx.gaussiantest I/filesize: createScaleDownBmp: Bitmap压缩后文件大小 = 31.68KB