private byte[] compressImage(Bitmap image) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int options = 60;
image.compress(Bitmap.CompressFormat.JPEG, options, baos);// 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
while (baos.toByteArray().length / 1024 >= 32) { // 循环判断如果压缩后图片是否大于100kb,大于继续压缩
options -= 10;// 每次都减少10
baos.reset();// 重置baos即清空baos
image.compress(Bitmap.CompressFormat.JPEG, options, baos);// 这里压缩options%,把压缩后的数据存放到baos中
}
return baos.toByteArray();
}