AspectHelper { public static RectangleF zoom(RectangleF src, float ar) { if (is_4_3(ar)) { RectangleF r169 = fitInside(RectF_16_9, src); r169.height = r169.width * 9 / 16; return r169.center(src).aspectRatioScale(src).center(src); } else { RectangleF r43 = fitInside(RectF_4_3, src); RectangleF r169 = fitInside(RectF_16_9, r43); r169.height=r169.width*9/16; return r169.center(src).aspectRatioScale(src).center(src); } }  static boolean is_4_3(float ar); static boolean is_16_9(float ar); static boolean is_ar_equals(float ar1, float ar2); static float minScale(RectangleF src, RectangleF dest); static float maxScale(RectangleF src, RectangleF dest); static RectangleF fitInside(RectangleF src, RectangleF dest); static RectangleF fitOutside(RectangleF src, RectangleF dest); static RectangleF fitWidth(RectangleF src, RectangleF dest); static RectangleF fitHeight(RectangleF src, RectangleF dest); static RectangleF scaleAndCenterRect(RectangleF src, RectangleF dest, float scale); static RectangleF stretch(RectangleF src, float ar); static RectangleF zoom(RectangleF src, float ar); static final RectangleF RectF_4_3; static final RectangleF RectF_16_9; static final float ar_4_3; static final float ar_16_9; static final float ar_tolerance; }
@Test public void testZoom169() throws Exception { RectangleF r169 = new RectangleF(0,0,1920,1080); Rectangle test = AspectHelper.zoom(r169, AspectHelper.ar_16_9).asIntRect(); assertEquals(-320, test.x); assertEquals(-180, test.y); assertEquals(2560, test.width); assertEquals(1440, test.height); r169 = new RectangleF(0,0,1280,720); RectangleF rtrans = AspectHelper.zoom(r169, AspectHelper.ar_16_9).translateImmutable(r169, new RectangleF(0,0,1920,1080)); System.out.println(rtrans); test= rtrans.asIntRect(); assertEquals(-320, test.x); assertEquals(-180, test.y); assertEquals(2560, test.width); assertEquals(1440, test.height); }
@Test public void testZoom43() throws Exception { RectangleF r43 = new RectangleF(0,0,640,480); Rectangle test = AspectHelper.zoom(r43, AspectHelper.ar_4_3).asIntRect(); System.out.println(test); assertEquals(0, test.x); assertEquals(-80, test.y); assertEquals(640, test.width); assertEquals(640, test.height); RectangleF rtrans = test.asFloatRect().translateImmutable(test.asFloatRect().position(0,0), new RectangleF(0,0,1920,1080)); System.out.println(rtrans); test= rtrans.asIntRect(); assertEquals(0, test.x); assertEquals(-135, test.y); assertEquals(1920, test.width); assertEquals(1080, test.height); }