Skip to content

Instantly share code, notes, and snippets.

@sprejjs
Created July 26, 2017 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sprejjs/0a3d7e552899cd946a2328c9ef59d13b to your computer and use it in GitHub Desktop.
Save sprejjs/0a3d7e552899cd946a2328c9ef59d13b to your computer and use it in GitHub Desktop.
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