压缩Bitmap到指定宽高
public static Bitmap compressBitmapToGivenWidthAndHeight(Bitmap bitmap, double newWidth, double newHeight) {
//获取这个图片的宽和高
float width = bitmap.getWidth();
float height = bitmap.getHeight();
//创建操作图片用的matrix对象
Matrix matrix = new Matrix();
//计算宽高缩放率
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
//压缩Bitmap
matrix.postScale(scaleWidth, scaleHeight);
Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, (int) width, (int) height, matrix, true);
return newBitmap;
}