The problem when using scaling is how to re-position the GraphicsPath exactly to the original position (the fixed position) after scaling.
As I mentioned in the question about the way I tried to achieve this but I realize that it's not easy and unstable depending on the scaling factors. And I tried to find out another way. Here it is:
The steps are:
- Scale the GraphicsPath.
- Translate the GrahicsPath to the original position.
private void ScaleWithoutChangingPosition(GraphicsPath gp, float scalex, float scaley){
Matrix m = new Matrix();
m.Scale(scalex, scaley);
gp.Transform(m);
m.Reset();
float left = float.MaxValue, top = float.MaxValue;
foreach(PointF p in gp.PathPoints){
if(left > p.X) left = p.X;
if(top > p.Y) top = p.Y;
}
m.Translate(fixedPosition.X - left, fixedPosition.Y - top);
gp.Transform(m);
}
The important thing here is how I find the new location of GraphicsPath after scaling and it's surely exact as I want.
Thanks!