Java tutorial
//package com.java2s; public class Main { public static int getSampleSizeAutoFitToScreen(int vWidth, int vHeight, int bWidth, int bHeight) { if (vHeight == 0 || vWidth == 0) { return 1; } int ratio = Math.max(bWidth / vWidth, bHeight / vHeight); int ratioAfterRotate = Math.max(bHeight / vWidth, bWidth / vHeight); return Math.min(ratio, ratioAfterRotate); } }