Created
March 9, 2012 19:54
-
-
Save Richie97/2008332 to your computer and use it in GitHub Desktop.
Resizing Bitmaps
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 getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { | |
int width = bm.getWidth(); | |
int height = bm.getHeight(); | |
float scaleWidth = ((float) newWidth) / width; | |
float scaleHeight = ((float) newHeight) / height; | |
// CREATE A MATRIX FOR THE MANIPULATION | |
Matrix matrix = new Matrix(); | |
// RESIZE THE BIT MAP | |
matrix.postScale(scaleWidth, scaleHeight); | |
// RECREATE THE NEW BITMAP | |
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); | |
return resizedBitmap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment