本人项目中,对用到的图片的处理,全部放在一个工具类中了,这里mark一下
/** * 方法1 质量压缩 * * @param beforBitmap * @return */ public static Bitmap compressImage(Bitmap beforBitmap) { // 可以捕获内存缓冲区的数据,转换成字节数组。 ByteArrayOutputStream bos = new ByteArrayOutputStream(); if (beforBitmap != null) { // 第一个参数:图片压缩的格式;第二个参数:压缩的比率;第三个参数:压缩的数据存放到bos中 beforBitmap. compress(Bitmap.CompressFormat.JPEG, 100, bos); int options = 100; // 循环判断压缩后的图片是否是大于100kb,如果大于,就继续压缩,否则就不压缩 while (bos.toByteArray().length / 1024 > 100) { bos.reset();//