Bitmap bitMap = BitmapFactory.decodeFile(path); |
02 | int width = bitMap.getWidth(); |
03 | int height = bitMap.getHeight(); |
04 | // 设置想要的大小 |
05 | int newWidth = 500 ; |
06 | int newHeight = 400 ; |
07 | // 计算缩放比例 |
08 | float scaleWidth = (( float ) newWidth) / width; |
09 | float scaleHeight = (( float ) newHeight) / height; |
10 | // 取得想要缩放的matrix参数 |
11 | Matrix matrix = new Matrix(); |
12 | matrix.postScale(scaleWidth, scaleHeight); |
13 | // 得到新的图片 |
14 | bitMap = Bitmap.createBitmap(bitMap, 0 , 0 , width, height, matrix, true ); |