//傳入需要轉(zhuǎn)換成的指定寬高即可。
private void resizeBitmap(float newWidth,float newHeight){
//獲取原圖大小
int width = bitmap.getWidth();
int height = bitmap.getHeight();
//計算縮放比例
float scaleWidth = newWidth/width;
float scaleHeight = newHeight/height;
//矩陣
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth,scaleHeight);
//或matrix.setScale(scaleWidth,scaleHeight);
bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true);
}