Skip to content

Instantly share code, notes, and snippets.

@boyvanamstel
Created May 24, 2011 20:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boyvanamstel/989628 to your computer and use it in GitHub Desktop.
Save boyvanamstel/989628 to your computer and use it in GitHub Desktop.
Resize image in Android
// Source: http://www.anddev.org/resize_and_rotate_image_-_example-t621.html
// load the origial BitMap (500 x 500 px)
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.android);
int width = bitmapOrg.width();
int height = bitmapOrg.height();
int newWidth = 720;
float scaleWidth = ((float) newWidth) / width;
float ratio = ((float) scaled.getWidth()) / newWidth;
int newHeight = (int) (height / ratio);
float scaleHeight = ((float) newHeight) / height;
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
matrix.postRotate(45);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
@pcg92
Copy link

pcg92 commented May 8, 2017

What is scaled.getWidth() ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment