public static void AssertResolutionIsSupported(EmulatorSize resolution) { var aspectRatio = GetAspectRatio(resolution); if (aspectRatio == null) { throw new Exception($"不支持的分辨率: {resolution}"); } }
public static AspectRatio GetAspectRatio(EmulatorSize resolution) { var simplified = resolution.Simplify(); foreach (var ratio in SupportedAspectRatio) { if (ratio.W == simplified.Item1 && ratio.H == simplified.Item2) { return(ratio); } } return(null); }
private EmulatorSize GetResolutionDirectly() { var output = AdbShell("wm size"); var match = Regex.Match(output, "(\\d+)x(\\d+)"); if (!match.Success) { throw new Exception(AheadWithName("获取模拟器分辨率失败")); } var size = new EmulatorSize(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value)); return(size); }