Advertisement
Guest User

ScaleImageHeight

a guest
Jan 26th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1.     public static Point scaleImageHeightForScreen(Activity ctx, int imageId) {
  2.  
  3.         // Ref: http://andrew.hedges.name/experiments/aspect_ratio/
  4.  
  5.         BitmapDrawable bd=(BitmapDrawable) ctx.getResources().getDrawable(imageId);
  6.  
  7.         int imgHeight = bd.getBitmap().getHeight();
  8.         int imgWidth = bd.getBitmap().getWidth();
  9.  
  10.  
  11.         int scrWidth = 0;
  12.  
  13.         WindowManager w = ctx.getWindowManager();
  14.  
  15.         Display d = w.getDefaultDisplay();
  16.  
  17.         scrWidth = d.getWidth();
  18.  
  19.         double calcHeight = ((double)imgHeight / imgWidth) * scrWidth;
  20.  
  21.         return new Point(scrWidth, (int)calcHeight);
  22.  
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement