alitrun
alitrun

Reputation: 1218

How to rotate TPathData (vector path)?

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.

Upvotes: 4

Views: 327

Answers (2)

fpiette
fpiette

Reputation: 12322

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

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

Upvotes: 4

XylemFlow
XylemFlow

Reputation: 1023

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

Upvotes: 4

Related Questions