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;