Skip to content

Instantly share code, notes, and snippets.

@sprejjs

sprejjs/step15.java

Created Jul 26, 2017
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
You can’t perform that action at this time.