admin管理员组文章数量:1356716
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.
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
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
How can i do this?
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.
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
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
How can i do this?
Share Improve this question edited Jun 19, 2013 at 7:39 Shoaib Ijaz asked Jun 17, 2013 at 17:32 Shoaib IjazShoaib Ijaz 5,60712 gold badges62 silver badges88 bronze badges 3- 1 Possible duplicate Calculate a Ratio in C# – Dustin Kingen Commented Jun 17, 2013 at 17:38
- not sure where you got 107:90. I put those numbers into that site and got 167:125. Regardless, just follow the math on the site you linked and you'll be able to get any image ratio. – musicmunky Commented Jun 17, 2013 at 17:47
- yes i have correct the ratio 167: 125 – Shoaib Ijaz Commented Jun 19, 2013 at 7:39
1 Answer
Reset to default 7I 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.
private int FindHCF(int m, int n)
{
int temp, remainder;
if (m < n)
{
temp = m;
m = n;
n = temp;
}
while (true)
{
remainder = m % n;
if (remainder == 0)
return n;
else
m = n;
n = remainder;
}
}
So here is the rest of the code
int hcf = FindHcf(835, 625);
int factorW = 835 / hcf;
int factorH = 625 / hcf;
本文标签: cHow calculate aspect ratio from dimensions of imageStack Overflow
版权声明:本文标题:c# - How calculate aspect ratio from dimensions of image - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743981274a2571089.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论