How to rotate TPathData (vector path)?

Viewed 162

I have TPathData arrow and draw directly on Canvas. How to rotate TPathData? I know about rotating Tpath but I draw directly on Canvas (lines and arrows). I tried to rotate Tpath and the get Data string - but it is the same as before.

2 Answers

You have to create a rotation matrix and then apply it.

M := TMatrix.CreateRotation(DegToRad(90));  
PathData.ApplyMatrix(M);

Instead of rotating the TPathData, why not set the TCanvas matrix before drawing the path? This is probably more efficient because the GPU takes care of the rotation, and also more numerically stable since you won't lose any precision in your path data points if you're rotating many times.

msave := Image1.Bitmap.Canvas.Matrix;
Image1.Bitmap.Canvas.SetMatrix(TMatrix.CreateRotation(DegToRad(90)));
Image1.Bitmap.Canvas.DrawPath(PathData, 1);
Image1.Bitmap.Canvas.SetMatrix(msave); // Restore canvas matrix
Related