【问题标题】:scaling 4:3 points to 16:9 points将 4:3 点缩放为 16:9 点
【发布时间】:2016-01-30 07:11:45
【问题描述】:

我有一个点数组,它们的范围都在 x(0-512) 和 y(0-384) 之间,这意味着纵横比为 4:3。

如果我想在 16:9 显示器上完美地显示每个点,需要什么数学才能实现?

假设“ee”是我的 4:3 点,“point”是我需要的 16:9 点..

我想因为我试图在 1920:1080 的显示器上缩放它,这是 16:9 的纵横比

point = new PointF(ee.x * (1920 / 512), ee.y * (1080 / 384));

但这似乎有点不对劲。

有什么帮助吗?谢谢。

【问题讨论】:

  • perfectly 是什么意思?填充整个 16:9 显示器会破坏纵横比(圆圈会变成鸡蛋),还是保留纵横比并接受 3:4 图像左右两侧的黑色竖线?
  • 确保使用浮点数,然后在此处使用整数 1920 / 512 = 31080 / 382 = 2... 只需执行 1920.01080.0

标签: c# .net aspect-ratio


【解决方案1】:

除了将每个维度乘以一个整数之外,您无法完全匹配方面。这里唯一适合的整数是 2(因为 384 * 3 > 1080)...

所以你必须这样做:

point = new Point (ee.x * 2, ee.y * 2);

您可以将其居中:

point = new Point (ee.x * 2 + ((1920 - 512*2)/2), ee.y * 2 + ((1080 - 384*2)/2)));

希望对您有所帮助...

编辑:对于浮点数,您必须取乘数的最小值:

var multiplier = Math.Min(1920.0/512, 1080.0/384);
point = new Point (ee.x * multiplier + ((1920 - 512*multiplier)/2), ee.y * multiplier + ((1080 - 384*multiplier)/2)));

【讨论】:

  • 我很抱歉.. 我忘了说 PointF 而不是 Point。我也接受浮点值。
【解决方案2】:

您能否详细说明“关闭”是什么意思?

如果您的意思是图像看起来水平拉伸,那是因为纵横比比以前大了。如果您希望图像看起来像以前一样(但更大),您需要按纵横比缩放一个轴来修复它。

aspect_ratio_before = 4.0f / 3.0f;
aspect_ratio_after = 16.0f / 9.0f;

// This is equal to 4/3.
aspect_ratio_difference = aspect_ratio_after / aspect_ratio_before;

// I squish the X axis here.
point.x /= aspect_ratio_difference;

// Alternatively, you can also multiply point.y by the 
// aspect_ratio_difference, though that will stretch the Y axis instead.
// Use only one!
// point.y *= aspect_ratio_difference;

免责声明:我之前没有使用过.net,所以我不知道它的渲染引擎的所有细节。这是基于我使用 OpenGL 和缩放的经验。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    相关资源
    最近更新 更多