Skip to content

Instantly share code, notes, and snippets.

@sprejjs
Created July 26, 2017 12:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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