C# GDI Invert Graphics 在 X 轴上翻转

发布于 2024-08-12 08:21:20 字数 104 浏览 1 评论 0原文

我正在使用 Graphics 类绘制一系列点。我正在读取点数组。无论出于何种原因,渲染的图像都是颠倒的(在 X 轴上翻转)。有没有一种简单的方法告诉 Graphics 类绘制“颠倒”?非常感谢。

I am drawing a series of Points using the Graphics class. I am reading from a Point array. For whatever reason the rendered image is upside down (flipped on the X axis). Is there a simple way to tell the Graphics class to draw "upside down" ? Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无法回应 2024-08-19 08:21:20

听起来不像是倒着画的,而是倒着给出的坐标。

检查您期望的坐标是否具有正确的原点。默认情况下,0,0 应位于屏幕的左上角。

编辑:您应该能够通过在绘制每个点时更改 Y 来进行补偿,以使用公式 Y = 高度 - Y。

It sounds not like it's drawing upside down, but like it's being given the coordinates upside down.

Check that you're expecting coordinates with the right origin. 0,0 should be by default top-left of your screen.

EDIT: You should be able to compensate by changing Y on each point as you draw it to use the formula Y = height - Y.

九命猫 2024-08-19 08:21:20

您应该注意,大多数绘图系统中图形的默认方向是从显示屏顶部到显示屏底部。为了弥补这一点,您需要知道查看区域的预期高度,然后从该高度中减去您的坐标。这将反转方向,并相对于查看区域的底部设置您的图形。

假设您有两个点指定为以及 300(宽)x 200(高)的视口。

{{0, 0}, {100, 200}}

当在可视区域中绘制时,将被映射到。这给我们带来了以下几点。

{{0, 200}, {100, 0}}

还有一些机制可以将映射模式切换为笛卡尔样式坐标,这可能会与您的源数据匹配,但通常会避免,因为它会重新映射已经补偿默认方向的所有其他内容。

如果您确实希望这样做,可以使用 Windows 中的 SetMapMode() 函数来实现此目的。

SetMapMode() @ MSDN

这是 P /调用函数的签名。 (从
pinvoke.net: setmapmode (gdi32) )

[DllImport("gdi32.dll")]
static extern int SetMapMode(IntPtr hdc, int fnMapMode);

编辑:

还有一种方法可以实现这一点,但我个人还没有尝试过。

Graphics.TransformPoints Method @ MSDN

这允许您指定坐标系, Graphics 对象将为您完成映射。在您的情况下,您可能希望使用 CooperativeSpace.World 或 CooperativeSpace.Page 作为第一个参数来调用它,并使用 CooperativeSpace.Device 作为第二个参数来调用它。

You should note that the default orientation or direction of graphics in most drawing systems is from top of display to the bottom of the display. To compensate for this, you need to know the intended height of your viewing area, and then subtract your coordinates from that height. This will reverse the orientation, and set your figures relative to the bottom of the viewing area.

Let's say you have two points specified as <x,y> and a viewport that is 300 (w) x 200 (h).

{{0, 0}, {100, 200}}

When drawing in the viewing area, <x, y> will get mapped to <x, 200-y>. This gives us the following points.

{{0, 200}, {100, 0}}

There are also mechanisms to switch the mapping mode to Cartesian style coordinates, which will probably match your source data, but is usually avoided because it will remap everything else that has already compensated for the default orientation.

The SetMapMode() function in Windows can be used for this purpose if this is what you really wish.

SetMapMode() @ MSDN

Here's the P/Invoke signature of the function. (from
pinvoke.net: setmapmode (gdi32) )

[DllImport("gdi32.dll")]
static extern int SetMapMode(IntPtr hdc, int fnMapMode);

edit:

There's one more way to accomplish this, which I personally haven't tried.

Graphics.TransformPoints Method @ MSDN

This allows you to specify coordinate systems, and the Graphics object will do the mapping for you. In your case, you may wish to call it with CoordinateSpace.World or CoordinateSpace.Page as the first argument, and CoordinateSpace.Device as the second.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文