Calculate coefficient
The aspect ratio of a window, screen, image, or other rectangular object is simply its width divided by its height.
So, for example, on a full HD screen (1920 pixels wide by 1080 pixels), the aspect ratio is:
ratio = width / height = 1920 / 1080 = 1.7778
Please note that 1920/1080 == 16/9
: this is why this is often referred to as aspect ratio 16:9
. If you think of the colon as a division, you get the same aspect ratio as if you measured the screen yourself.
Also interesting: if you know the aspect ratio (for example, 16: 9 or 1.7778) and you know the height of the screen (for example, 1080 pixels), you can get the screen width by multiplying:
width = height * ratio = 1080 * 1.7778 = 1920 // round result to nearest integer // Or, if you remember that 16:9 means 16/9, then: width = height * ratio = 1080 * (16 / 9) = 1920
Likewise, you can get the screen height from the aspect ratio and width by dividing:
height = width / ratio = 1920 / 1.7778 = 1080 // Again, rounding to integer // Or... height = width / ratio = 1920 / (16 / 9) = 1080
The only really tricky thing is how some mobile devices handle aspect ratios can be a little confusing. For example, when you turn your phone on it, it naturally appears that the long edge is the width of the screen and the short edge is the height, however IIRC, most phone operating systems actually maintain the same width and height and leave that for you to deal with. the fact that the screen is mostly just tilted on the side.
source to share