I want to get the aspect ratio of the monitor as two digits: width and height. For example, 4 and 3, 5 and 4, 16 and 9.
I wrote code for this task. Maybe this is an easier way to do this? For example, some library function = \
public struct AspectRatio
{
int _height;
public int Height
{
get
{
return _height;
}
}
int _width;
public int Width
{
get
{
return _width;
}
}
public AspectRatio(int height, int width)
{
_height = height;
_width = width;
}
}
public sealed class Aux
{
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);
}
static int GCD(int a, int b)
{
return b == 0 ? a : GCD(b, a % b);
}
}
source
share