如何根据图像尺寸计算纵横比

时间:2022-06-01 21:26:38

I am using Jcrop for cropping image so i want to calculate ratio of height and width of image but problem is that there is no limit of maximum height and width.

我使用Jcrop裁剪图像,所以我想计算图像的高度和宽度的比例,但问题是没有最大高度和宽度的限制。

when user upload image then i want to get height,width ratio so on cropping it should be crop with respect to aspect ratio for example

当用户上传图像然后我想获得高度,宽度比等所以裁剪它应该是关于纵横比的裁剪例如

Width=835, Height=625 aspect ratio would be 167: 125

宽度= 835,高度= 625纵横比为167:125

i have calculated this ratio from following link Aspect ratio calculator

我从以下链接宽高比计算器计算了这个比率

I don't want to cacalute new height,width. I just want to calculate ratio 167: 125

我不想要新的高度,宽度。我只想计算比例167:125

How can i do this?

我怎样才能做到这一点?

1 个解决方案

#1


5  

I think you are looking for HCF (Highest Common Factor) but the ratio (Width:835,Height:625) will be 167:125. Here is the function by which you can calculate HCF between 2 numbers.

我认为你正在寻找HCF(最高公因数),但比例(宽度:835,身高:625)将是167:125。这是您可以计算2个数字之间的HCF的函数。

 private int FindHCF(int m, int n)
 {
     int temp, reminder;
     if (m < n)
     {
         temp = m;
         m = n;
         n = temp;
     }
     while (true)
     {
         reminder = m % n;
         if (reminder == 0)
             return n;
         else
             m = n;
         n = reminder;
     }
 }

So here is the rest of the code

所以这是代码的其余部分

int hcf = FindHcf(835, 625);
int factorW = 835 / hcf;
int factorH = 625 / hcf;

#1


5  

I think you are looking for HCF (Highest Common Factor) but the ratio (Width:835,Height:625) will be 167:125. Here is the function by which you can calculate HCF between 2 numbers.

我认为你正在寻找HCF(最高公因数),但比例(宽度:835,身高:625)将是167:125。这是您可以计算2个数字之间的HCF的函数。

 private int FindHCF(int m, int n)
 {
     int temp, reminder;
     if (m < n)
     {
         temp = m;
         m = n;
         n = temp;
     }
     while (true)
     {
         reminder = m % n;
         if (reminder == 0)
             return n;
         else
             m = n;
         n = reminder;
     }
 }

So here is the rest of the code

所以这是代码的其余部分

int hcf = FindHcf(835, 625);
int factorW = 835 / hcf;
int factorH = 625 / hcf;