Advertisement
matt5784

Untitled

Jun 18th, 2012
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1.     private Drawable resizeImage(int resId, int w, int h)
  2.     {
  3.           // load the origial Bitmap
  4.           Bitmap BitmapOrg = BitmapFactory.decodeResource(getResources(), resId);
  5.           int width = BitmapOrg.getWidth();
  6.           int height = BitmapOrg.getHeight();
  7.           int newWidth = w;
  8.           int newHeight = h;
  9.           // calculate the scale
  10.           float scaleWidth = ((float) newWidth) / width;
  11.           float scaleHeight = ((float) newHeight) / height;
  12.           // create a matrix for the manipulation
  13.           Matrix matrix = new Matrix();
  14.           matrix.postScale(scaleWidth, scaleHeight);
  15.           Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0,width, height, matrix, true);
  16.           return new BitmapDrawable(resizedBitmap);
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement