【发布时间】:2016-10-15 17:54:13
【问题描述】:
我从一个名为line 的列表中放置坐标,用我的panel1 缩放它们并使用GraphicsPath 绘制连接它们的线。我遇到的问题是图像垂直翻转,可能是由于 panel1 的 (0,0) 坐标位于左上角,而不是我的正常坐标源自左下角为零的坐标系。代码如下:
Graphics G = e.Graphics;
GraphicsPath gp = new GraphicsPath();
foreach (var line in tockeKoordinate)
{
gp.AddLine((float)(line.startX), (float)(line.startY),
(float)(line.endX), (float)(line.endY));
gp.CloseFigure();
}
var rect = gp.GetBounds();
var scale = Math.Min(1f * (int)(panel1.ClientSize.Width) / rect.Width,
1f * (int)(panel1.ClientSize.Height) / rect.Height);
using (Pen pen = new Pen(Color.DarkGreen, 0.0001f))
{
G.SmoothingMode = SmoothingMode.AntiAlias;
G.Clear(Color.White);
G.ScaleTransform(scale, scale);
G.TranslateTransform(-rect.X, -rect.Y);
G.DrawPath(pen, gp);
}
我一直在搜索,不知何故与 G.TranslateTransform 行有关,但在值中添加减号前缀的成功率为零...
【问题讨论】:
-
您真的应该只使用 (0, 0) 位于左上角的正常图形约定,而不是从数学约定中执行它然后稍后翻转。
-
请参阅here 如何使用翻转的图形对象。请注意,您需要知道画布的大小!
-
@Jashaszun 源 GPS 坐标是这样的,而且很多坐标都无法手动更改。
-
您可以在将它们添加到 GraphicsPath 之前更改它们。
-
@TaW 最终解决了,就像您在链接解决方案中所说的那样,顺序确实很重要 :)
标签: c# graphics panel coordinate-systems