Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Point scaleImageHeightForScreen(Activity ctx, int imageId) {
- // Ref: http://andrew.hedges.name/experiments/aspect_ratio/
- BitmapDrawable bd=(BitmapDrawable) ctx.getResources().getDrawable(imageId);
- int imgHeight = bd.getBitmap().getHeight();
- int imgWidth = bd.getBitmap().getWidth();
- int scrWidth = 0;
- WindowManager w = ctx.getWindowManager();
- Display d = w.getDefaultDisplay();
- scrWidth = d.getWidth();
- double calcHeight = ((double)imgHeight / imgWidth) * scrWidth;
- return new Point(scrWidth, (int)calcHeight);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement