Created
July 26, 2017 12:07
-
-
Save sprejjs/0a3d7e552899cd946a2328c9ef59d13b to your computer and use it in GitHub Desktop.
This file contains 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
private static final float PREFERRED_WIDTH = 250; | |
private static final float PREFERRED_HEIGHT = 250; | |
public static Bitmap resizeBitmap(Bitmap bitmap) { | |
int width = bitmap.getWidth(); | |
int height = bitmap.getHeight(); | |
float scaleWidth = PREFERRED_WIDTH / width; | |
float scaleHeight = PREFERRED_HEIGHT / height; | |
Matrix matrix = new Matrix(); | |
matrix.postScale(scaleWidth, scaleHeight); | |
Bitmap resizedBitmap = Bitmap.createBitmap( | |
bitmap, 0, 0, width, height, matrix, false); | |
bitmap.recycle(); | |
return resizedBitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment