Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Drawable resizeImage(int resId, int w, int h)
- {
- // load the origial Bitmap
- Bitmap BitmapOrg = BitmapFactory.decodeResource(getResources(), resId);
- int width = BitmapOrg.getWidth();
- int height = BitmapOrg.getHeight();
- int newWidth = w;
- int newHeight = h;
- // calculate the scale
- float scaleWidth = ((float) newWidth) / width;
- float scaleHeight = ((float) newHeight) / height;
- // create a matrix for the manipulation
- Matrix matrix = new Matrix();
- matrix.postScale(scaleWidth, scaleHeight);
- Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0,width, height, matrix, true);
- return new BitmapDrawable(resizedBitmap);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement