private MousePoint calculate(int wrapperH, int wrapperW, int realImgH, int realImgW) { MousePoint re = new MousePoint(0,0); int relativeImgH = 0; int relativeImgW = 0; float wraperTL = (float)wrapperH / wrapperW; float realImgTL = (float)realImgH / realImgW; if (wraperTL >= realImgTL) { relativeImgW = wrapperW; relativeImgH = (int)(relativeImgW * realImgTL); } else { relativeImgH = wrapperH; relativeImgW = (int)(relativeImgH / realImgTL); } re.setX(relativeImgW); re.setY(relativeImgH); return re; }