これは非常に遅い返信ですが、私はこれをはるかに簡単な方法で解決しました。他の人が感謝することを知っています.
アスペクト比 (10 進数に相当) を知っているので、画面の解像度を既に知っていると仮定しています。画面の幅と高さの最大公約数を解くことで、アスペクト比 (整数:整数) を見つけることができます。
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
お役に立てれば。
注: これは、一部の解像度では機能しません。コメントには詳細情報が含まれています。