AspectHelper { public static RectangleF stretch(RectangleF src, float ar) { if (is_4_3(ar)) { return src.copy(); } else { return fitInside(RectF_4_3, 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 testStretch4_3() { RectangleF r43 = new RectangleF(0,0,640,480); RectangleF stretch43 = AspectHelper.stretch(r43, r43.getAR()); Rectangle trans = stretch43.translateImmutable(r43, new RectangleF(0,0,1920,1080)).asIntRect(); System.out.println(trans); assertEquals(0, trans.x); assertEquals(0, trans.y); assertEquals(1920, trans.width); assertEquals(1080, trans.height); }
@Test public void testStretch16_9() { RectangleF r169 = new RectangleF(0,0,1280,720); RectangleF stretch169 = AspectHelper.stretch(r169, r169.getAR()); Rectangle trans = stretch169.translateImmutable(r169, new RectangleF(0,0,1920,1080)).asIntRect(); System.out.println(trans); assertEquals(-320, trans.x); assertEquals(0, trans.y); assertEquals(2560, trans.width); assertEquals(1080, trans.height); }