when my TransformGroup combines ScaleTransform, RotateTransform, and TranslateTransform simultaneously, it is required that the image can be moved, rotated with the center of the image as the rotation center, and scaled with the mouse position as the center. My code movement and rotation are normal, and scaling alone is also normal. However, when I rotate and scale again, the scaling center is no longer the center of the mouse. I think my scaling center calculation is incorrect, May I ask how to calculate the correct position? TransformGroup
RenderTransformGroup = new TransformGroup();
RenderTransformGroup.Children.Add(ScaleTransform);
RenderTransformGroup.Children.Add(RotateTransform);
RenderTransformGroup.Children.Add(TranslateTransform);
rotate operate
RotateTransform.Angle = angle;
RotateTransform.CenterX = (int)(imageWidth * ScaleTransform.ScaleX / 2);
RotateTransform.CenterY = (int)(imageHeight * ScaleTransform.ScaleY / 2);
scale operate
MouseWheel
var point= e.GetPosition(Canvas);
var inversePoint = RenderTransformGroup.Inverse.Transform(point);
ScaleTransform.ScaleX += scale;
ScaleTransform.ScaleY += scale;
TranslateTransform.X = point.X - inversePoint.X * ScaleTransform.ScaleX;
TranslateTransform.Y = point.Y - inversePoint.Y * ScaleTransform.ScaleY;
translate operate
MouseLeftButtonDown
PreviousPoint = e.GetPosition(image.Parent as Canvas);
MouseMove
CurrentPoint = e.GetPosition(image.Parent as Canvas);
TranslateTransform.X += (CurrentPoint.X - PreviousPoint.X);
TranslateTransform.Y += (CurrentPoint.Y - PreviousPoint.Y);
PreviousPoint = CurrentPoint;
I hope to correctly calculate the zoom center centered around the mouse point when zooming in and out after rotation