RenderTransform vs PushTransform

I have a form (red path below) and I have to apply TranslateTransform and ScaleTransform to this path. But if I use Shape RenderTransform as follows:

Path MyPath = new Path { Fill = new SolidColorBrush(Colors.Red) }; MyPath.Data = MyPathGeometry; TransformGroup transf = new TransformGroup(); transf.Children.Add(new TranslateTransform(50, 50)); transf.Children.Add(new ScaleTransform(2, 2)); MyPath.RenderTransform = transf; 

I get a drawing of this type:

enter image description here

Instead, if I use a DrawingContext PushTransform this way:

 DrawingVisual MyPath = new DrawingVisual(); using (DrawingContext context = MyPath.RenderOpen()) { context.PushTransform(new TranslateTransform(50, 50)); context.PushTransform(new ScaleTransform(2, 2)); context.DrawGeometry(Brushes.Red, null, MyPathGeometry); } 

I get a drawing of this type:

enter image description here

Why are the two paths located differently? What is the difference between using PushTransform and RenderTransform? How can I get the same result in both cases? Thanks.

+3
source share
1 answer

The difference is simply the order in which the transforms are applied.

In the first case (TransformGroup), you first translate (50, 50), then scale to (2, 2). In the second case (PushTransform), you first scale and then translate.

Transforms in a TransformGroup are executed in sequential order with the first in the first order if the pressed transforms are executed in an order similar to the stack or the last at the beginning.

+9
source

Source: https://habr.com/ru/post/914911/


All Articles