这是一个非常晚的回复,但我已经用一种更简单的方法解决了这个问题,我知道其他人会很感激。
我假设您已经知道屏幕分辨率,因为您知道纵横比(十进制等效值)。您可以通过求解屏幕宽度和高度之间的最大公因数来找到纵横比(整数:整数)。
public int greatestCommonFactor(int width, int height) {
return (height == 0) ? width : greatestCommonFactor(height, width % height);
}
这将返回屏幕宽度和高度之间的最大公因数。要找到实际的纵横比,只需将屏幕宽度和高度除以最大公因数。所以...
int screenWidth = 1920;
int screenHeight = 1080;
int factor = greatestCommonFactor(screenWidth, screenHeight);
int widthRatio = screenWidth / factor;
int heightRatio = screenHeight / factor;
System.out.println("Resolution: " + screenWidth + "x" + screenHeight;
System.out.println("Aspect Ratio: " + widthRatio + ":" + heightRatio;
System.out.println("Decimal Equivalent: " + widthRatio / heightRatio;
这输出:
Resolution: 1920x1080
Aspect Ratio: 16:9
Decimal Equivalent: 1.7777779
希望这可以帮助。
注意:这不适用于某些分辨率。评论包含更多信息。