Reputation: 407
I'm putting coordinates from a List called line
, scaling them with my panel1 and drawing the lines that connect them using GraphicsPath
. The problem I'm getting is that the image is flipped vertically, probably due to to the panel1's (0,0)
cordinates being in the top left as opposed as my normal coordinates originating from the coordinate system that has the zeroes in the bottom left. The code is as follows:
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);
}
I've been searching and it somehow has got to do to the G.TranslateTransform line, but I've had zero success adding minus prefixes to the values...
Upvotes: 0
Views: 2198
Reputation: 407
Solved, with the help of TaW and James Lambert. Needed to flip the axis by negating the Y parameters of the ScaleTransform
, but also bring the canvas down using TranslateTransform
:
G.TranslateTransform(0, +panel1.ClientSize.Height);
G.ScaleTransform(scale, -scale);
Upvotes: 1
Reputation: 129
TranslateTransform just moves things around but cannot flip anything. You can flip it by negating one of the parameters to ScaleTransform.
Upvotes: 2