//传入需要转换成的指定宽高即可。
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);
}
网友评论