RenderTransform vs PushTransform

时光毁灭记忆、已成空白 提交于 2020-01-14 18:55:32

问题


I have a shape (the red path below) and i have to apply to this path a TranslateTransform and a ScaleTransform transformation. But if i use the Shape RenderTransform property in this way:

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:

Instead, if I use DrawingContext PushTransform method in 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:

Why the two paths are placed in a different way? What is the difference between using PushTransform and RenderTransform? How could i get the same result in both cases? Thanks.


回答1:


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

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

The transformations in a TransformGroup are executed in a sequential, first-in-first-out order, wheras the pushed transforms are executed in a stack-like or last-in-first-out order.



来源:https://stackoverflow.com/questions/10453095/rendertransform-vs-pushtransform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!