모니터의 종횡비를 너비와 높이의 두 자릿수로 가져 오려고합니다. 예를 들어 4, 3, 5, 4, 16 및 9가 있습니다.모니터의 가로 세로 비율 가져 오기
그 작업을위한 코드를 작성했습니다. 어쩌면 그렇게하는 것이 더 쉬운 방법일까요? 예를 들어, 일부 라이브러리 함수 = \
/// <summary>
/// Aspect ratio.
/// </summary>
public struct AspectRatio
{
int _height;
/// <summary>
/// Height.
/// </summary>
public int Height
{
get
{
return _height;
}
}
int _width;
/// <summary>
/// Width.
/// </summary>
public int Width
{
get
{
return _width;
}
}
/// <summary>
/// Ctor.
/// </summary>
/// <param name="height">Height of aspect ratio.</param>
/// <param name="width">Width of aspect ratio.</param>
public AspectRatio(int height, int width)
{
_height = height;
_width = width;
}
}
public sealed class Aux
{
/// <summary>
/// Get aspect ratio.
/// </summary>
/// <returns>Aspect ratio.</returns>
public static AspectRatio GetAspectRatio()
{
int deskHeight = Screen.PrimaryScreen.Bounds.Height;
int deskWidth = Screen.PrimaryScreen.Bounds.Width;
int gcd = GCD(deskWidth, deskHeight);
return new AspectRatio(deskHeight/gcd, deskWidth/gcd);
}
/// <summary>
/// Greatest Common Denominator (GCD). Euclidean algorithm.
/// </summary>
/// <param name="a">Width.</param>
/// <param name="b">Height.</param>
/// <returns>GCD.</returns>
static int GCD(int a, int b)
{
return b == 0 ? a : GCD(b, a % b);
}
}
제가 생각하기에 라이브러리 기능은 없습니다. 어쨌든 답변 주셔서 감사합니다;) –
내 화면 해상도는 1813x1024이며 왜 "1024 : 1813"을 반환했는지 확신 할 수 없습니까? –
내 화면 해상도는 1366 * 768이지만 384 : 683을 반환합니다! 내가 무엇을 할 수 있을지 – user3290286