Created
November 27, 2018 09:42
-
-
Save flyfire/f90af22bb26aa6b8e3c71e8ecdec6154 to your computer and use it in GitHub Desktop.
[ScaleBitmap] scale bitmap #bitmap #scale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //缩放图片大小 | |
| public Bitmap scaleBitmap(Bitmap bitmap, int newWidth, int newHeight) { | |
| Bitmap b = bitmap; | |
| int width = b.getWidth(); | |
| int height = b.getHeight(); | |
| // 计算缩放比例 | |
| float scaleWidth = ((float) newWidth) / width; | |
| float scaleHeight = ((float) newHeight) / height; | |
| // 取得想要缩放的matrix参数 | |
| Matrix matrix = new Matrix(); | |
| matrix.postScale(scaleWidth, scaleHeight); | |
| // 得到新的图片 | |
| return Bitmap.createBitmap(b, 0, 0, width, height, matrix, true); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment