当前位置: 代码迷 >> 综合 >> 计算分辨率长宽比(等比例缩放)
  详细解决方案

计算分辨率长宽比(等比例缩放)

热度:93   发布时间:2024-01-25 01:07:51.0
    /*** 计算长宽比* @param fromWidth         原始宽度* @param fromHeight        原始高度* @param toWidthOrHeight   目标宽度或高度* @param isWidth           <code>toWidthOrHeight</code>是宽度还是高度* @return                  <code>isWidth</code>为true则返回结果为高度,否则为宽度*/public static int clacAspectRatio(int fromWidth, int fromHeight,int toWidthOrHeight, boolean isWidth) {double ret;double ratio = (double) fromHeight / (double) fromWidth;if( isWidth ) {ret = (double) toWidthOrHeight * ratio;}else {ret = (double) toWidthOrHeight / ratio;}return (int) ret;}
    public static void main(String[] a) {System.out.println( "1920*" + clacAspectRatio( 1440, 2880, 1920, false ) );System.out.println( "1080*" + clacAspectRatio( 1440, 2880, 1080, true ) );}//处理结果
//==> 1920*960
//==> 1080*2160

 

  相关解决方案