Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 确定源分辨率是否属于指定的纵横比_C#_.net_Vb.net_Aspect Ratio_Imaging - Fatal编程技术网

C# 确定源分辨率是否属于指定的纵横比

C# 确定源分辨率是否属于指定的纵横比,c#,.net,vb.net,aspect-ratio,imaging,C#,.net,Vb.net,Aspect Ratio,Imaging,我想确定源分辨率是否属于C#或VB.NET中指定的纵横比 目前我写了这样一篇文章: /// -------------------------------------------------------------------------- /// <summary> /// Determine whether the source resolution belongs to the specified aspect ratio. /// </summary> /// -

我想确定源分辨率是否属于C#或VB.NET中指定的纵横比

目前我写了这样一篇文章:

/// --------------------------------------------------------------------------
/// <summary>
/// Determine whether the source resolution belongs to the specified aspect ratio.
/// </summary>
/// --------------------------------------------------------------------------
/// <param name="resolution">
/// The source resolution.
/// </param>
/// 
/// <param name="aspectRatio">
/// The aspect ratio.
/// </param>
/// --------------------------------------------------------------------------
/// <returns>
/// <see langword="true"/> if the source resolution belongs to the specified aspect ratio; 
/// otherwise, <see langword="false"/>.
/// </returns>
/// ----------------------------------------------------------------------------------------------------
public static bool ResolutionIsOfAspectRatio(Size resolution, Point aspectRatio) {

    return (resolution.Width % aspectRatio.X == 0) && 
           (resolution.Height % aspectRatio.Y == 0);

}
用法示例:

Size resolution = new Size(1920, 1080);
Point aspectRatio = new Point(16, 9);

bool result = ResolutionIsOfAspectRatio(resolution, aspectRatio);

Console.WriteLine(result);
我只是想确保我没有遗漏纵横比的概念,这可能会在使用我编写的函数时导致意外的结果

然后,我的问题是:该算法对所有情况都适用吗?如果不适用,我应该做哪些修改才能正确执行此操作


编辑:我注意到算法完全错误,它采用640x480作为16:9的纵横比。关于如何计算的基本知识,我读得不够。

您的计算中有一个错误。单独修改每个值并不能验证纵横比

e、 g

是真的,但是

Point aspect = new Point(16, 10); //1080%10==0 invalid and true!
这也是事实

正确的计算方法是

bool result = res.Width / aspect.X == res.Height / aspect.Y; //1920/16 == 1080/9

我知道在评论框里感谢某人是不可取的,但我还是要谢谢你。我刚刚在这里读了一篇文章,这可能会改变。我们可能被允许作为人类(简短地)说“请”和“谢谢”。
Point aspect = new Point(16, 10); //1080%10==0 invalid and true!
bool result = res.Width / aspect.X == res.Height / aspect.Y; //1920/16 == 1080/9