1. 像素压缩
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
//缩放图片
bitmapOptions.inSampleSize = 8;
Bitmap bitmap = BitmapFactory.decodeFile(path,bitmapOptions);
2. 质量压缩
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,100,byteArrayOutputStream);
int size = 100;
//若图片大于500kb,则继续压缩
while (byteArrayOutputStream.toByteArray().length / 1024 > 500)
{
byteArrayOutputStream.reset();
size -= 1;
bitmap.compress(Bitmap.CompressFormat.JPEG,size,byteArrayOutputStream);
}